C++ʵս(һ)??ͨѶ¼ϵͳ

ڣ2021-09-18 15:31:22


תԣhttps://github.com/AnkerLeng/Cpp-0-1-Resource.git
Ƶhttps://www.bilibili.com/video/av41559729?p=31



1ϵͳ

ͨѶ¼һԼ¼ˡϢĹߡ


̳ҪC++ʵһͨѶ¼ϵͳ


ϵͳҪʵֵĹ£


ϵˣͨѶ¼ˣϢԱ䡢ϵ绰ͥסַ¼1000ʾϵˣʾͨѶ¼ϵϢɾϵˣɾָϵ˲ϵˣ鿴ָϵϢ޸ϵˣ޸ָϵϵˣͨѶ¼Ϣ˳ͨѶ¼˳ǰʹõͨѶ¼
2Ŀ

Ŀ£


Ŀļ
2.1 Ŀ

vs2017󣬵ĿµC++Ŀ

дĿƣѡĿ·


2.2ļ



ӳɹЧͼ

ˣĿѴ



ûѡܵĽ


˵Чͼ


װʾý void showMenu()mainе÷װõĺ


#include
using namespace std;

//˵
void showMenu()
{
cout << "***************************" << endl;
cout << "***** 1ϵ *****" << endl;
cout << "***** 2ʾϵ *****" << endl;
cout << "***** 3ɾϵ *****" << endl;
cout << "***** 4ϵ *****" << endl;
cout << "***** 5޸ϵ *****" << endl;
cout << "***** 6ϵ *****" << endl;
cout << "***** 0˳ͨѶ¼ *****" << endl;
cout << "***************************" << endl;
}

int main() {

showMenu();

system("pause");

return 0;
}


˳ͨѶ¼ϵͳ


˼·ûͬѡ񣬽벻ͬĹܣѡswitch֧ṹܹд


ûѡ0ʱִ˳ѡȲҲ˳



int main() {

int select = 0;

while (true)
{
showMenu();

cin >> select;

switch (select)
{
case 1: //ϵ
break;
case 2: //ʾϵ
break;
case 3: //ɾϵ
break;
case 4: //ϵ
break;
case 5: //޸ϵ
break;
case 6: //ϵ
break;
case 0: //˳ͨѶ¼
cout << "ӭ´ʹ" << endl;
system("pause"); //
return 0; //
break;
default:
break;
}
}

system("pause");

return 0;
}

Чͼ




ʵϵ˹ܣϵΪ1000ˣϵϢԱ䡢ϵ绰ͥסַ


ϵʵֲ裺


ϵ˽ṹͨѶ¼ṹmainдͨѶ¼װϵ˺ϵ˹
5.1 ϵ˽ṹ

ϵϢԱ䡢ϵ绰ͥסַ


£


#include //stringͷļ
//ϵ˽ṹ
struct Person
{
string m_Name; //
int m_Sex; //Ա1 2Ů
int m_Age; //
string m_Phone; //绰
string m_Addr; //סַ
};

5.2 ͨѶ¼ṹ

ʱͨѶ¼ṹУάһΪ1000Ĵϵ˵飬¼ǰͨѶ¼ϵ



#define MAX 1000 //

//ͨѶ¼ṹ
struct Addressbooks
{
struct Person personArray[MAX]; //ͨѶ¼бϵ
int m_Size; //ͨѶ¼Ա
};

5.3 mainдͨѶ¼

ϵ˺װúmainдһͨѶ¼ҪһֱάͨѶ¼


mianʼλӣ

//ͨѶ¼
Addressbooks abs;
//ʼͨѶ¼
abs.m_Size = 0;

5.4 װϵ˺

˼·ϵǰжͨѶ¼Ƿ˾ͲӣδϵϢ뵽ͨѶ¼


ϵ˴룺


//1ϵϢ
void addPerson(Addressbooks *abs)
{
//жϵ绰Ƿ
if (abs->m_Size == MAX)
{
cout << "ͨѶ¼޷" << endl;
return;
}
else
{
//
string name;
cout << "" << endl;
cin >> name;
abs->personArray[abs->m_Size].m_Name = name;

cout << "Ա" << endl;
cout << "1 -- " << endl;
cout << "2 -- Ů" << endl;

//Ա
int sex = 0;
while (true)
{
cin >> sex;
if (sex == 1 || sex == 2)
{
abs->personArray[abs->m_Size].m_Sex = sex;
break;
}
cout << "";
}

//
cout << "䣺" << endl;
int age = 0;
cin >> age;
abs->personArray[abs->m_Size].m_Age = age;

//ϵ绰
cout << "ϵ绰" << endl;
string phone = "";
cin >> phone;
abs->personArray[abs->m_Size].m_Phone = phone;

//ͥסַ
cout << "ͥסַ" << endl;
string address;
cin >> address;
abs->personArray[abs->m_Size].m_Addr = address;

//ͨѶ¼
abs->m_Size++;

cout << "ӳɹ" << endl;
system("pause");
system("cls"); //
}
}

5.5 ϵ˹

ѡУѡ1ϵˣǿԲ¸ù


switch case Уcase1ӣ


case 1: //ϵ
addPerson(&abs);
break;

Чͼ


6ʾϵ

ʾͨѶ¼еϵϢ


ʾϵʵֲ裺


װʾϵ˺ʾϵ˹
6.1 װʾϵ˺

˼·жǰͨѶ¼ûԱʾ¼Ϊգ0ʾͨѶ¼Ϣ


ʾϵ˴룺


//2ʾϵϢ
void showPerson(Addressbooks * abs)
{
if (abs->m_Size == 0)
{
cout << "ǰ¼Ϊ" << endl;
}
else
{
for (int i = 0; i < abs->m_Size; i++)
{
cout << "" << abs->personArray[i].m_Name << " ";
cout << "Ա" << (abs->personArray[i].m_Sex == 1 ? "" : "Ů") << " ";
cout << "䣺" << abs->personArray[i].m_Age << " ";
cout << "绰" << abs->personArray[i].m_Phone << " ";
cout << "סַ" << abs->personArray[i].m_Addr << endl;
}
}

system("pause");
system("cls");

}

6.2 ʾϵ˹

switch caseУcase 2


case 2: //ʾϵ
showPerson(&abs);
break;

Чͼ


7ɾϵ

ɾָϵ


ɾϵʵֲ裺


װϵǷڷװɾϵ˺ɾϵ˹
7.1 װϵǷ

˼·


ɾϵǰҪжûϵǷڣɾʾûûҪɾϵ


ǿ԰ѼϵǷڷװһУڣϵͨѶ¼еλãڷ-1


ϵǷڴ룺


//жǷڲѯԱڷλãڷ-1
int isExist(Addressbooks * abs, string name)
{
for (int i = 0; i < abs->m_Size; i++)
{
if (abs->personArray[i].m_Name == name)
{
return i;
}
}
return -1;
}

7.2 װɾϵ˺

ûϵжϸͨѶ¼Ƿд


ҵɾʾɾɹ


鲻ʾ޴ˡ


//3ɾָϵϢ
void deletePerson(Addressbooks * abs)
{
cout << "Ҫɾϵ" << endl;
string name;
cin >> name;

int ret = isExist(abs, name);
if (ret != -1)
{
for (int i = ret; i < abs->m_Size; i++)
{
abs->personArray[i] = abs->personArray[i + 1];
}
abs->m_Size--;
cout << "ɾɹ" << endl;
}
else
{
cout << "޴" << endl;
}

system("pause");
system("cls");
}

7.3 ɾϵ˹

switch case Уcase3ӣ


case 3: //ɾϵ
deletePerson(&abs);
break;

Чͼ







鿴ָϵϢ


ϵʵֲ


װϵ˺Բָϵ
8.1 װϵ˺

ʵ˼·жûָϵǷڣʾϢʾ޴ˡ


ϵ˴룺


//4ָϵϢ
void findPerson(Addressbooks * abs)
{
cout << "Ҫҵϵ" << endl;
string name;
cin >> name;

int ret = isExist(abs, name);
if (ret != -1)
{
cout << "" << abs->personArray[ret].m_Name << " ";
cout << "Ա" << abs->personArray[ret].m_Sex << " ";
cout << "䣺" << abs->personArray[ret].m_Age << " ";
cout << "绰" << abs->personArray[ret].m_Phone << " ";
cout << "סַ" << abs->personArray[ret].m_Addr << endl;
}
else
{
cout << "޴" << endl;
}

system("pause");
system("cls");

}

8.2 Բָϵ

switch case Уcase4ӣ


case 4: //ϵ
findPerson(&abs);
break;

Чͼ






9޸ϵ

޸ָϵ


޸ϵʵֲ


װ޸ϵ˺޸ϵ˹
9.1 װ޸ϵ˺

ʵ˼·ûϵˣҳɹ޸IJʧʾ޴


޸ϵ˴룺


//5޸ָϵϢ
void modifyPerson(Addressbooks * abs)
{
cout << "Ҫ޸ĵϵ" << endl;
string name;
cin >> name;

int ret = isExist(abs, name);
if (ret != -1)
{
//
string name;
cout << "" << endl;
cin >> name;
abs->personArray[ret].m_Name = name;

cout << "Ա" << endl;
cout << "1 -- " << endl;
cout << "2 -- Ů" << endl;

//Ա
int sex = 0;
while (true)
{
cin >> sex;
if (sex == 1 || sex == 2)
{
abs->personArray[ret].m_Sex = sex;
break;
}
cout << "";
}

//
cout << "䣺" << endl;
int age = 0;
cin >> age;
abs->personArray[ret].m_Age = age;

//ϵ绰
cout << "ϵ绰" << endl;
string phone = "";
cin >> phone;
abs->personArray[ret].m_Phone = phone;

//ͥסַ
cout << "ͥסַ" << endl;
string address;
cin >> address;
abs->personArray[ret].m_Addr = address;

cout << "޸ijɹ" << endl;
}
else
{
cout << "޴" << endl;
}

system("pause");
system("cls");

}

9.2 ޸ϵ˹

switch case Уcase 5ӣ


case 5: //޸ϵ
modifyPerson(&abs);
break;

Чͼ


鲻ָϵ

ҵϵˣ޸ijɹ

ٴβ鿴ͨѶ¼ȷ޸


10ϵ

ͨѶ¼Ϣ


ϵʵֲ


װϵ˺ϵ
10.1 װϵ˺

ʵ˼· ͨѶ¼ϵϢֻҪͨѶ¼¼ϵΪ0߼ռɡ


ϵ˴룺


//6ϵ
void cleanPerson(Addressbooks * abs)
{
abs->m_Size = 0;
cout << "ͨѶ¼" << endl;
system("pause");
system("cls");
}

10.2 ϵ

switch case Уcase 6 ӣ


case 6: //ϵ
cleanPerson(&abs);
break;

Чͼ


ͨѶ¼

ٴβ鿴Ϣʾ¼Ϊ


ˣͨѶ¼ϵͳɣ

Ƽ