Question #43305
Write a C++ program that stores in a file the following information for students: name, address, phone number, age, and major field. Your program should use structures to represent a student’s record. In addition, your program should allow you to add, delete, search, and modify records.
1
Expert's answer
2014-06-17T11:53:40-0400
#include <iostream>#include <string>#include <vector>#include <fstream>#include <cstdlib>using namespace std;struct Student{   string name;   char adress[100];   unsigned int phone_number;   unsigned int age;};void init (vector<Student>& add){   system("cls");   Student st;   cout<<"Input name - ";   cin>>st.name;   cout<<"Input phone number - ";   cin>>st.phone_number;   cout<<"Input age - ";   cin>>st.age;   cout<<"Input adress - ";   cin.ignore();   cin.getline(st.adress,100);   system("cls");   add.push_back(st);}int  find_st(const vector<Student>& add){   system("cls");      string choise;    cout<<"Please enter name student - ";   cin>>choise;   for (size_t i = 0; i<add.size();i++)   {      if (add[i].name==choise)       {         return i;      }   }   cout<<"Search is unsuccessful "<<endl;   system("pause");   return -1;}void Del(vector<Student>& add,int choise){   system("cls");      add.erase(add.begin() + choise);   cout<<"Delete successful!"<<endl;   system("pause");   system("cls");   }void modify(vector<Student>& add ,int choise){   system("cls");      cout<<"Name - "<<add[choise].name<<" Modify - name - ";   cin>>add[choise].name;   cout<<"Adress - "<<add[choise].adress<<" Modify - adress - ";   cin.ignore();   cin.getline(add[choise].adress,100);   cout<<"Phone number - "<<add[choise].phone_number<<" Modify - phone number - ";   cin>>add[choise].phone_number;   cout<<"Age - "<<add[choise].age<<" Modify - age - ";   cin>>add[choise].age;   cout<<"Modify successful"<<endl;   system("pause");   system("cls");   }void menu (){   system("cls");   cout<<"Press 1 to add student"<<endl;   cout<<"Press 2 to find and work with student"<<endl;   cout<<"Press 0 to exit"<<endl;}void menu (int x){   system("cls");   cout<<"Search is successful "<<endl;   cout<<"Press 1 to modify student"<<endl;   cout<<"Press 2 to delete student"<<endl;   cout<<"Press 0 to exit"<<endl;}void work_with_St(vector<Student>& add){   int search_ind;   char qv;   do    {      search_ind=find_st(add);      if (search_ind==-1) return;      menu(1);      cin>>qv;         switch (qv)      {         case '1':modify(add,search_ind);qv='0';break;         case '2':Del(add,search_ind);qv='0';break;         case '0':break;         default:cout<<"Wrong answer !Retry"<<endl;      }   }while (qv!='0');   }int main(int argc, char** argv) {   vector<Student> Stud;   int search_Indx=0;   char qv = '\0';   do    {      menu();      cin>>qv;      switch (qv)      {         case '1'  : init(Stud);break;         case '2'  : work_with_St(Stud);break;         case '0'  : break;         default:cout<<"Wrong answer !Retry"<<endl;      }      system("cls");   }while (qv!='0');   return 0;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS