最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于C++實(shí)現(xiàn)信息管理系統(tǒng)

 更新時(shí)間:2022年03月18日 14:37:49   作者:qq_996852067  
這篇文章主要為大家詳細(xì)介紹了基于C++實(shí)現(xiàn)信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

基于c++設(shè)計(jì)的信息管理系統(tǒng),供大家參考,具體內(nèi)容如下

1、使用類+函數(shù)實(shí)現(xiàn)
2、使用STL容器的vector
3、fstream的文件存儲(chǔ)方式
4、xls文件讀入 寫(xiě)出
5、數(shù)據(jù)的四大功能增刪改查
6、一定的輸入容錯(cuò)能力

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <windows.h>
#include <vector>
#include <fstream>
#include <iterator>

#define Num 20
#define FALSE 0
#define TRUE 1
#define PATH "./file.xls"

using namespace std;

class LiangshanHeros
{

public:
? ? char name[Num]; //梁山好漢姓名
? ? int age; ? ? ? ?//年齡
? ? char loc[Num]; ?//籍貫
? ? double bounty; ? //懸賞金

public:

? ? LiangshanHeros()
? ? {
? ? ? ? age = 18;
? ? ? ? bounty = 6666;
? ? }

? ? LiangshanHeros(char* _name, int _age, char* _loc, double the_bounty)
? ? {
? ? ? ? strcpy(name, _name);
? ? ? ? age = _age;
? ? ? ? strcpy(loc, _loc);
? ? ? ? bounty = the_bounty;
? ? }

? ? ~LiangshanHeros()
? ? {

? ? }


public:
? ? char* getName();
? ? char* getLoc();
? ? double getBounty();
? ? int getAge();

public:
? ? int setName(char*);
? ? int setAge(int);
? ? int setLoc(char*);
? ? int setprice(double);

public:
? ? void showMenu();
};

class params : public LiangshanHeros {

public :
? ? params() {

? ? }
? ? ~params() {

? ? }

public:

? ? void InitSet();
? ? void showMensu();
};

char* LiangshanHeros::getName()
{

? ? return name;
}

char* LiangshanHeros::getLoc()
{

? ? return loc;
}

double LiangshanHeros::getBounty()
{

? ? return bounty;
}

int LiangshanHeros::getAge()
{

? ? return age;
}

int LiangshanHeros::setName(char* _name)
{
? ? if (strlen(_name) > 20 || strlen(_name) < 2)
? ? {
? ? ? ? cout << "重新輸入梁山好漢姓名 長(zhǎng)度[0 - 20]" << endl;
? ? ? ? return FALSE;
? ? }
? ? else
? ? {
? ? ? ? strcpy(name, _name);
? ? ? ? return TRUE;
? ? }

}

int LiangshanHeros::setAge(int _age)
{
? ? if (_age > 100 || _age < 0)
? ? {
? ? ? ? cout << "重新輸入年齡 大小[0 - 100]" << endl;
? ? ? ? return FALSE;
? ? }
? ? else
? ? {
? ? ? ? age = _age;
? ? ? ? return TRUE;
? ? }

}

int LiangshanHeros::setLoc(char* _loc)
{
? ? if (strlen(_loc) > 20 || strlen(_loc) < 2)
? ? {
? ? ? ? cout << "重新輸入梁山好漢籍貫 長(zhǎng)度[0 - 20]" << endl;
? ? ? ? return FALSE;
? ? }
? ? else
? ? {
? ? ? ? strcpy(loc, _loc);
? ? ? ? return TRUE;
? ? }
}

int LiangshanHeros::setprice(double the_Bouney)
{
? ? if (the_Bouney < 0)
? ? {
? ? ? ? cout << "重新輸入價(jià)格 大小[0 - &]" << endl;
? ? ? ? return FALSE;
? ? }
? ? else
? ? {
? ? ? ? bounty = the_Bouney;
? ? ? ? return TRUE;
? ? }
}


void setAll(LiangshanHeros* par)
{
? ? while (1)
? ? {
? ? ? ? cout << "輸入梁山好漢姓名: " << endl;
? ? ? ? char n[Num] = { 0 };
? ? ? ? cin >> n;
? ? ? ? if (par->setName(n) == TRUE) break;
? ? }

? ? while (1)
? ? {
? ? ? ? cout << "輸入年齡: " << endl;
? ? ? ? int a;
? ? ? ? cin >> a;
? ? ? ? if (par->setAge(a) == TRUE) break;
? ? }

? ? while (1)
? ? {
? ? ? ? cout << "輸入梁山好漢籍貫: " << endl;
? ? ? ? char l[Num] = { 0 };
? ? ? ? cin >> l;
? ? ? ? if (par->setLoc(l) == TRUE) break;
? ? }

? ? while (1)
? ? {
? ? ? ? cout << "輸入賞金: " << endl;
? ? ? ? double p;
? ? ? ? cin >> p;
? ? ? ? if (par->setprice(p) == TRUE) break;
? ? }
}

LiangshanHeros* set()
{
? ? LiangshanHeros* par = new LiangshanHeros;
? ? //do set
? ? setAll(par);
? ? return par;
}

void search(vector<LiangshanHeros*>& vec, char* name)
{
? ? int i = 0;
? ? int flag = 0;

? ? for (i = 0; i < vec.size(); i++)
? ? {
? ? ? ? if (strcmp(vec[i]->name, name) == 0)
? ? ? ? {
? ? ? ? ? ? cout << "查找成功 " << endl;
? ? ? ? ? ? cout << vec[i]->getName() << endl;
? ? ? ? ? ? cout << vec[i]->getAge() << endl;
? ? ? ? ? ? cout << vec[i]->getLoc() << endl;
? ? ? ? ? ? cout << vec[i]->getBounty() << endl;
? ? ? ? ? ? flag = 1;
? ? ? ? }
? ? }

? ? //case faild
? ? if (flag == 0)
? ? {
? ? ? ? cout << "查找失敗" << endl;
? ? }

}

void deletePar(vector<LiangshanHeros*>& vec, char* name)
{
? ? int i = 0;
? ? int flag = 0;

? ? for (i = 0; i < vec.size(); i++)
? ? {
? ? ? ? if (strcmp(vec[i]->name, name) == 0)
? ? ? ? {
? ? ? ? ? ? cout << "查找成功 " << endl;
? ? ? ? ? ? cout << vec[i]->getName() << endl;
? ? ? ? ? ? cout << vec[i]->getAge() << endl;
? ? ? ? ? ? cout << vec[i]->getLoc() << endl;
? ? ? ? ? ? cout << vec[i]->getBounty() << endl;

? ? ? ? ? ? vec.erase(vec.begin() + i);

? ? ? ? ? ? //sp case
? ? ? ? ? ? i--;
? ? ? ? ? ? cout << "刪除成功 " << endl;
? ? ? ? ? ? flag = 1;
? ? ? ? }
? ? }

? ? if (flag == 0)
? ? {
? ? ? ? cout << "未找到該梁山好漢" << endl;
? ? }
}

void change(vector<LiangshanHeros*>& vec, char* name)
{
? ? int i = 0;
? ? int flag = 0;

? ? for (i = 0; i < vec.size(); i++)
? ? {
? ? ? ? if (strcmp(vec[i]->name, name) == 0)
? ? ? ? {
? ? ? ? ? ? cout << "查找成功 " << endl;
? ? ? ? ? ? cout << vec[i]->getName() << endl;
? ? ? ? ? ? cout << vec[i]->getAge() << endl;
? ? ? ? ? ? cout << vec[i]->getLoc() << endl;
? ? ? ? ? ? cout << vec[i]->getBounty() << endl;
? ? ? ? ? ? cout << "請(qǐng)輸入需要修改變量的值:" << endl;
? ? ? ? ? ? cout << "1.梁山好漢姓名 ?2.年齡 3.籍貫 4.賞金" << endl;
? ? ? ? ? ? int choice;

? ? ? ? ? ? while (1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cin >> choice;
? ? ? ? ? ? ? ? if (choice > 4 || choice < 0) continue;
? ? ? ? ? ? ? ? else break;
? ? ? ? ? ? }

? ? ? ? ? ? cout << "輸入修改后的值" << endl;

? ? ? ? ? ? switch (choice)
? ? ? ? ? ? {
? ? ? ? ? ? case 1:
? ? ? ? ? ? {
? ? ? ? ? ? ? ? while (1)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cout << "輸入梁山好漢姓名: " << endl;
? ? ? ? ? ? ? ? ? ? char n[Num] = { 0 };
? ? ? ? ? ? ? ? ? ? cin >> n;
? ? ? ? ? ? ? ? ? ? if (vec[i]->setName(n) == TRUE) break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? case 2:
? ? ? ? ? ? {
? ? ? ? ? ? ? ? while (1)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cout << "輸入年齡: " << endl;
? ? ? ? ? ? ? ? ? ? int a;
? ? ? ? ? ? ? ? ? ? cin >> a;
? ? ? ? ? ? ? ? ? ? if (vec[i]->setAge(a) == TRUE) break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? case 3:
? ? ? ? ? ? {
? ? ? ? ? ? ? ? while (1)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cout << "輸入梁山好漢籍貫: " << endl;
? ? ? ? ? ? ? ? ? ? char l[Num] = { 0 };
? ? ? ? ? ? ? ? ? ? cin >> l;
? ? ? ? ? ? ? ? ? ? if (vec[i]->setLoc(l) == TRUE) break;
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? case 4:
? ? ? ? ? ? {
? ? ? ? ? ? ? ? while (1)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cout << "輸入賞金: " << endl;
? ? ? ? ? ? ? ? ? ? double p;
? ? ? ? ? ? ? ? ? ? cin >> p;
? ? ? ? ? ? ? ? ? ? if (vec[i]->setprice(p) == TRUE) break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? flag = 1;
? ? ? ? }
? ? }


? ? if (flag == 0)
? ? {
? ? ? ? cout << "未找到該梁山好漢" << endl;
? ? }
}

void inputFile(vector<LiangshanHeros*>& vec)
{
? ? ofstream ofs;
? ? ofs.open(PATH, ios::ate | ios::binary);
? ? int i = 0;

? ? if (vec.size() < 0)
? ? {
? ? ? ? cout << "還未錄入數(shù)據(jù)" << endl;
? ? ? ? return;
? ? }

? ? for (i = 0; i < vec.size(); i++)
? ? {
? ? ? ? ofs << vec[i]->name << "\t" << vec[i]->age << "\t" << vec[i]->loc << "\t" << vec[i]->bounty;
? ? ? ? ofs << "\n";
? ? }

? ? cout << "數(shù)據(jù)錄入成功 存儲(chǔ)于 ./file.xls中" << endl;

? ? ofs.close();
}

void outputFile(vector<LiangshanHeros*>& vec)
{
? ? ifstream ifs;
? ? ifs.open(PATH, ios::binary | ios::in);
? ? if (ifs.fail()) {

? ? ? ? cout << "文件未創(chuàng)建 請(qǐng)先錄入數(shù)據(jù)" << endl;
? ? ? ? return;
? ? }
? ? int i = vec.size();
? ? int age;
? ? double price;
? ? char loc[Num] = { 0 };
? ? char name[Num] = { 0 };

? ? //判斷是否為文件結(jié)尾
? ? while (!ifs.eof())
? ? {
? ? ? ? LiangshanHeros* par = new LiangshanHeros;
? ? ? ? ifs >> par->name >> par->age >> par->loc >> par->bounty;
? ? ? ? vec.push_back(par);
? ? }

? ? cout << "file.xls 文件讀入成功 ?數(shù)據(jù)已寫(xiě)入" << endl;

? ? ifs.close();
}

void showAllParam(vector<LiangshanHeros*>& vec)
{
? ? int i = 0;

? ? for (i = 0; i < vec.size(); i++)
? ? {
? ? ? ? cout << "這是 第" << i + 1 << "位梁山好漢 :" << endl;
? ? ? ? cout << " ? 姓名 :" << vec[i]->name << endl;
? ? ? ? cout << " ? 年齡 :" << vec[i]->age << endl;
? ? ? ? cout << " ? 籍貫 :" << vec[i]->loc << endl;
? ? ? ? cout << " ? 賞金 :" << vec[i]->bounty << endl;
? ? ? ? cout << endl;
? ? }
}

void LiangshanHeros::showMenu()
{
? ? HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);//句柄
? ? SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED);
? ? printf("\t基于梁山好漢的文件存儲(chǔ)系統(tǒng)\n");
? ? SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY | FOREGROUND_RED);
? ? printf("〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");
? ??
? ? printf("\t丨 1.添加梁山好漢 ? ? ? ? ? ? ? ?\n");
? ? printf("\t丨 2.查找梁山好漢 ? ? ? ? \n");
? ? printf("\t丨 3.刪除梁山好漢 ? ? ? ? \n");
? ? printf("\t丨 4.修改梁山好漢信息 ? ? ? ? \n");
? ? printf("\t丨 5.讀取已存在信息 ? ? ? ? ? ? ? ? \n");
? ? printf("\t丨 6.保存信息 ? ? ? ? ? ? ? ?\n");
? ? printf("\t丨 7.查閱所有信息 ? ? ? ? ? ? ? ? \n");
? ? printf("\t丨 8.退出 ? ? ? ? ? ? ?\n");
? ? SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY | FOREGROUND_RED);
? ? printf("〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n\t");
? ? SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY | FOREGROUND_BLUE);
? ? printf("輸入您的選擇(1-8):");
}

int main()
{
? ? system("mode con cols=135 lines=30");//控制臺(tái) 寬度135 高度20

? ? HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);//句柄
? ? SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY | FOREGROUND_RED);

? ? LiangshanHeros* par = new LiangshanHeros;
? ? par->showMenu();
? ? vector<LiangshanHeros*> vec;
? ? char name[Num] = { 0 };

? ? SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY | FOREGROUND_RED);
? ? while (1)
? ? {
? ? ? ? int num;
? ? ? ? cin >> num;
? ? ? ? switch (num)
? ? ? ? {
? ? ? ? case 1:
? ? ? ? {
? ? ? ? ? ? vec.push_back(set());
? ? ? ? ? ? cout << "添加成功" << endl;
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 2:
? ? ? ? {
? ? ? ? ? ? printf("輸入查找的梁山好漢名稱:");
? ? ? ? ? ? cin >> name;
? ? ? ? ? ? search(vec, name);
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 3:
? ? ? ? {
? ? ? ? ? ? printf("輸入刪除的梁山好漢名稱:");
? ? ? ? ? ? cin >> name;
? ? ? ? ? ? deletePar(vec, name);
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 4:
? ? ? ? {
? ? ? ? ? ? printf("輸入查找的梁山好漢名稱:");
? ? ? ? ? ? cin >> name;
? ? ? ? ? ? change(vec, name);
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 5:
? ? ? ? {
? ? ? ? ? ? outputFile(vec);
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 6:
? ? ? ? {
? ? ? ? ? ? inputFile(vec);
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 7:
? ? ? ? {
? ? ? ? ? ? showAllParam(vec);
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 8:
? ? ? ? {
? ? ? ? ? ? cout << "kill process .. " << endl;
? ? ? ? ? ? exit(0);
? ? ? ? ? ? break;
? ? ? ? }

? ? ? ? }
? ? ? ? system("pause");
? ? ? ? system("cls");
? ? ? ? par->showMenu();
? ? }
? ? return 0;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C語(yǔ)言如何利用異或進(jìn)行兩個(gè)值的交換詳解

    C語(yǔ)言如何利用異或進(jìn)行兩個(gè)值的交換詳解

    最近在工作中遇到了兩個(gè)值交換的需求,發(fā)現(xiàn)自己對(duì)異或有些忘記,所以索性寫(xiě)出來(lái),方便以后需要的時(shí)候參考學(xué)習(xí),下面這篇文章主要給大家介紹了關(guān)于C語(yǔ)言如何利用異或進(jìn)行兩個(gè)值的交換的相關(guān)資料,需要的朋友可以參考下。
    2017-09-09
  • 簡(jiǎn)單講解哈希表

    簡(jiǎn)單講解哈希表

    本文主要介紹了哈希表簡(jiǎn)單知識(shí)及C語(yǔ)言實(shí)現(xiàn)哈希表實(shí)例,文中利用圖片以及代碼簡(jiǎn)單講解了相關(guān)知識(shí),感興趣的小伙伴可以多多學(xué)習(xí)這篇文章
    2021-09-09
  • C++內(nèi)存分區(qū)模型超詳細(xì)講解

    C++內(nèi)存分區(qū)模型超詳細(xì)講解

    在了解內(nèi)存分區(qū)之前,我們先來(lái)聊一聊為什么要進(jìn)行內(nèi)存分區(qū)。在進(jìn)行了內(nèi)存分區(qū)之后,在不同的區(qū)域存放的數(shù)據(jù),會(huì)有不同的生命周期,從而會(huì)讓程序員的編程變得更加靈活
    2022-11-11
  • 講解C++中的枚舉類型以及聲明新類型的方法

    講解C++中的枚舉類型以及聲明新類型的方法

    這篇文章主要介紹了講解C++中的枚舉類型以及聲明新類型的方法,是C預(yù)言入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-09-09
  • C++浮點(diǎn)數(shù)類型詳情

    C++浮點(diǎn)數(shù)類型詳情

    這篇文章主要介紹了C++浮點(diǎn)數(shù)類型,浮點(diǎn)數(shù)是C++的第二組基本類型,它能夠表示帶小數(shù)部分的數(shù)字。不僅如此,浮點(diǎn)數(shù)的范圍也比int更大,可以表示更大范圍的數(shù)字。下面來(lái)我們大家一起來(lái)學(xué)習(xí)學(xué)習(xí)內(nèi)容
    2021-11-11
  • C++實(shí)現(xiàn)多源最短路徑之Floyd算法示例

    C++實(shí)現(xiàn)多源最短路徑之Floyd算法示例

    這篇文章主要介紹了C++實(shí)現(xiàn)多源最短路徑之Floyd算法,結(jié)合實(shí)例形式分析了多源最短路徑之Floyd算法的原理、實(shí)現(xiàn)方法及核心代碼,需要的朋友可以參考下
    2017-08-08
  • Qt中關(guān)聯(lián)容器QMap,QMultiMap,QHash,QMultiHash的使用

    Qt中關(guān)聯(lián)容器QMap,QMultiMap,QHash,QMultiHash的使用

    本文主要介紹了Qt中關(guān)聯(lián)容器QMap,QMultiMap,QHash,QMultiHash的使用,這些關(guān)聯(lián)容器在Qt中提供了靈活而強(qiáng)大的數(shù)據(jù)結(jié)構(gòu)選項(xiàng),根據(jù)具體的需求和使用場(chǎng)景,您可以選擇適合的容器來(lái)存儲(chǔ)和管理數(shù)據(jù),感興趣的可以了解一下
    2023-09-09
  • 淺談C語(yǔ)言中的注釋風(fēng)格小結(jié)

    淺談C語(yǔ)言中的注釋風(fēng)格小結(jié)

    今天小編就為大家分享一篇淺談C語(yǔ)言中的注釋風(fēng)格小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12
  • C++中string的模擬實(shí)現(xiàn)

    C++中string的模擬實(shí)現(xiàn)

    這篇文章主要為大家詳細(xì)介紹了C++中string的模擬實(shí)現(xiàn),感興趣的小伙伴們可以參考一下
    2016-08-08
  • C++實(shí)現(xiàn)LeetCode(692.前K個(gè)高頻詞)

    C++實(shí)現(xiàn)LeetCode(692.前K個(gè)高頻詞)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(692.前K個(gè)高頻詞),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08

最新評(píng)論

延川县| 孝感市| 金坛市| 印江| 渑池县| 永宁县| 兴城市| 郎溪县| 汕尾市| 增城市| 乡城县| 柳州市| 巴南区| 鹤山市| 全州县| 彭泽县| 明溪县| 乌审旗| 且末县| 西乌珠穆沁旗| 会宁县| 海兴县| 鹿泉市| 民勤县| 巫溪县| 衡山县| 扬中市| 山丹县| 栾川县| 印江| 自贡市| 滨海县| 南涧| 枣阳市| 奇台县| 华容县| 新营市| 广东省| 大名县| 濮阳县| 鄂尔多斯市|