the codes below is not complete
bacause i have a problem in determining biggest size of array
first,the program will ask user to enter number
number '1' for add id,
numer '2' for delele id,
alhough say 'delete' but just need replace it enough
for example,as you can see
i have set 4 elements for the array
if i choose id[2] to delete
then id[3](the last size of array) will repalce id[2]
so the problem is what if i choose menu'1' to add new id (call it "id[4]")
how can i determine id[4] to replace id[2] if i want to delete id[2]
*user can add more than 1 id and go back to menu for delete other id.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include <iostream>
#include <string>
using namespace std;
void addstudent(string fid[])
{
char type;
for (int a=2; a<=199; a++)
{
cout<<"Enter ID :\n";
cout<<"eg : 10000"<<endl;
cin>>fid[a];
cin.ignore();
cout<<"Do you want continue to add id(YES press Y or NO press N) :\n";
cin>>type;
if(type == 'Y' || type == 'y')
continue;
else
break;
}
}
void removestudent(string fid[])
{
string searchid4;
char remove;
for (int b=0;b<10;b++)
{
cout<<"Enter ID you wan to delete :"<<endl;
cout<<"eg : 10000"<<endl;
cin>>searchid4;
for(int d=0; d<=199; d++)
{
if(searchid4 == fid[d])
{
//how to set code here?
}
}
}
}
int main()
{
string id[200];
int menu;
id[0]=1000;
id[1]=1001;
id[2]=1002;
id[3]=1003;
char back;
for(int z=0; z<=10; z++)
{
cout<<"MENU LIST\n";
cout<<"------\n";
cout<<"1) Add id\n";
cout<<"2) Delete id\n";
cout<<endl;
cout<<"Menu :";
cin>>menu;
cin.ignore();
cout<<endl;
if(menu == 1)
{
addstudent(id);
}
if (menu == 2)
{
removestudent(id);
}
cout<<endl;
cout<<"Do you want back to MeNU LIST (YES press Y or NO press N) :\n";
cin>>back;
if(back == 'Y' || back =='y')
continue;
else
break;
cout<<endl;
cout<<endl;
}
cout<<"The program is ending to run"<<endl;
cout<<"Please debug the program again"<<endl;
cout<<"Thank You"<<endl;
system("pause");
return 0;
}
|