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:";
  cout<<"Which field you want to update(1-7)?:";

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

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


  else if (column_index == 2)
    cout<<"Enter student's Sex(F or M):";
  else if (column_index == 3)
   cout<<"Enter student's quizz1 score:";
  else if (column_index == 4)
   cout<<"Enter student's quizz2 score:";
  else if (column_index == 5)
     cout<<"Enter student's assigment score:";
  else if (column_index == 6)
    cout<<"Enter student's mid term score:";
  else if (column_index == 7)
    cout<<"Enter student's final score:";
  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.";



Jagga comment


how can we create a scientific calculator???


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.