У меня есть задание создать систему учета студентов, в которой я должен ввести имя, адрес и имя студента. Я создал массив объектов размером 20 и в каждом объекте я получаю имя, адрес и cgpa от пользователя. Теперь пользователь не обязан вводить данные всех 20 объектов, а зависит от того, сколько записей он хочет ввести. Я создаю функцию для отображения только введенных записей, но проблема в том, что она также показывает записи, в которых пользователь не ввел ни одной записи. (извините за мой плохой английский).
void Input(){
int i,c;
string n,a;
cout << endl << "\t\t\t\t Enter Name of the Student : ";
cin >> n;
set_name(n);
cout << endl << "\t\t\t\t Enter ID of the Student : ";
cin >> i;
set_id(i);
cout << endl << "\t\t\t\t Enter CGPA of the Student : ";
cin >> c;
set_cgpa(c);
cout << endl << "\t\t\t\t Enter Address of the Student : ";
cin >> a;
set_address(a);
}
void Output(Student s[], int const){
for(int i = 0 ; i < 20 ; i++){
cout << endl << "\t\t\t\t The Name of Student is " << s[i].get_name() << "." << endl;
cout << endl << "\t\t\t\t The ID of Student is " << s[i].get_id() << "." << endl;
cout << endl << "\t\t\t\t The CGPA of Student is " << s[i].get_cgpa() << "." << endl;
cout << endl << "\t\t\t\t The Address of Student is " << s[i].get_address() << "." << endl << endl << endl;
}
system("pause");
}
int main(){
Student s[20];
int option;
for(int i = 0 ; i < 20 ; i++){
system("cls");
s[i].drawmenu();
cout << "\t\t\t\t\t Enter An Option : ";
cin >> option;
if(option == 1){
s[i].Input();
}
else if(option == 2){
s[i].Output(s,20);
}
else if(option == 3){
s[i].Search(s,20);
}
else if(option == 4){
s[i].Update(s,20);
}
else if(option == 5){
s[i].Delete(s,20);
}
else if(option == 6){
break;
}
else if(option != 1 || option != 2 || option != 3 || option != 4 || option != 5 || option != 6){
cout << endl << "\t\t\t\t Entered Option is Not Valid." << endl;
system("pause");
}
}
return 1;
}