C++ exercises solutions: update record


C++ structure exercise: update record

Step 7: Defining the update(struct student st[], int itemcount) method to update a specified record. The update process starts by asking the user to input the id of the record to be changed. The id value is check to make sure it really exists. If it exits the change to the target record can be made after asking the user to input the new value of the field that need change.

void update_rec(struct student st[],int itemcount){
  string id;
  int column_index;
  cout<<"Enter student's ID:";
  cin>>id;
  cout<<"Which field you want to update(1-7)?:";
  cin>>column_index;

  int index = search(st, id,itemcount);

  if (index != -1)
  
{
    if (column_index == 1)
    
{
      cout<<"Enter student's Name:";

      cin>>st[index].stname;
    
}

  else if (column_index == 2)
  
{
    cout<<"Enter student's Sex(F or M):";
    cin>>st[index].sex;
   
}
  else if (column_index == 3)
  
{
   cout<<"Enter student's quizz1 score:";
   cin>>st[index].quizz1;
 
}
  else if (column_index == 4)
 
{
   cout<<"Enter student's quizz2 score:";
   cin>>st[index].quizz2;
 
}
  else if (column_index == 5)
  
{
     cout<<"Enter student's assigment score:";
     cin>>st[index].assigment;
    
}
  else if (column_index == 6)
  
{
    cout<<"Enter student's mid term score:";
    cin>>st[index].midterm;
}
  else if (column_index == 7)
  
{
    cout<<"Enter student's final score:";
    cin>>st[index].final;
  
}
  else cout<<"Invalid column index";

  st[index].total = st[index].quizz1 + st[index].quizz2 + st[index].assigment + st[index].midterm + st[index].final;


 
}
  else cout<<"The record deosn't exits.Check the ID and try again.";


}




Comments

Jagga comment

 Jagga

hi
how can we create a scientific calculator???


2015-07-06



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.