Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, My code is almost finished but I need help with one part of the assignmen

ID: 3677218 • Letter: H

Question

Hello, My code is almost finished but I need help with one part of the assignment. Here are screenshots of what we have to do in the assignment and sample outputs: http://imgur.com/a/D2UYH

Here is my code: (This code works and does about 50-60% of what we have to do)

# include <iostream>
# include <stdlib.h>
# include <ctime>
# include <array>
# include <vector>
# include <string>

using namespace std;


class students {

public:
   void set_IDnum(string);
   void set_recd(int, string, string, vector<int> );
   void print_all_recd();
   void print_recd(int);
   void find_ID(int);


private:
   struct record {
       int IDnum;
       string first_name;
       string last_name;
       vector<int> prog;
   };  
   vector <record> student_records;
};


int main() {
   students stdn;

   string first_name, last_name;
   int IDnum;
   vector<int> prog;
   prog.resize(3);   
srand((unsigned)time(NULL));
for (int j = 0; j < 3; j++){
prog[j] = rand() % 101;
}
   cout << "Enter new records (ID first last):" << endl;
   for (int i = 0; i < 3; i++) {
       cout << " " << i+1 << " ";
       cin >> IDnum >> first_name >> last_name;

       // make new records
       stdn.set_recd(IDnum, first_name, last_name, prog);
   }
   bool checkVal = true;
   while(checkVal) {
       cout <<" Select Option from the List:" << endl;
       cout <<" 1. Print all student records 2. Search student record by ID 3. quit ";
       int opt; cin >> opt;

       switch (opt) {
           case 1: {
               stdn.print_all_recd();
               break;
           }
           case 2: {
               cout << " Enter ID to search record: ";
               int ID_search; cin >> ID_search;
               stdn.find_ID(ID_search);
               break;
           }
           case 3: {
               checkVal = false;
               break;
           }
       }
   }
}


void students::set_recd(int IDnum, string first_name, string last_name, vector<int> prog) {
   record vector_element = {IDnum, first_name, last_name, prog};
   student_records.push_back(vector_element);
}

void students::set_IDnum(string first_name) {
   for (int i = 0; i < student_records.size(); i++) {
       if (student_records[i].first_name == first_name){
           cout << " Enter the new name: ";
           string new_fname;
           string new_lname;
           cin >> new_fname >> new_lname;
           student_records[i].first_name = new_fname;
           student_records[i].last_name = new_lname;
           return;
           //This is the change_name function but it doesnt work properly
       }
   }
}


void students::print_all_recd() {
   cout << endl;
   cout << " Student ID First Last" << endl;

   for (int i = 0; i < student_records.size(); i++) {
       cout << " " << i+1;
       cout << " " << student_records[i].IDnum << " " << student_records[i].first_name
       << " " << student_records[i].last_name << " " << endl;
   }
}

void students::print_recd(int recrd_num) {
   cout << " ID First Last" << endl;
   cout << " " << student_records[recrd_num].IDnum << " " << student_records[recrd_num].first_name
   << " " << student_records[recrd_num].last_name << " " << endl;
}

void students::find_ID(int IDnum) {
   bool flag = false; int num;
   for (int i = 0; i < student_records.size(); i++) {
       if (student_records[i].IDnum == IDnum) {
           print_recd(i);
           flag = true;
           num = i; //will be used later to remove a student record based on ID number
       }
   }
   if (flag == false)
       cout << " No record found..." << endl;
}

I need help with adding those vectors and arrays at the end of each student record as their quiz grades and exam grades. I also need help with removing a student record based on the student ID. And I need help fixing my function for changing the name of an existing person. Your help would be much appreciated. Let me know if there is any more information you need. Thank you.

Explanation / Answer

I have written my code too cause Im confused with your code while adding marks so check both and make changes and compile to check for small errors.

Heres my code :
# include <iostream.h>
using namespace std;

using namespace std;


struct student{
    char firstname[50],lastname[50];
    int ID;
    float quiz[6],exam[6];
};

int main() {
     student stdn[40];
     int i,count;
       bool checkVal = true;
while(checkVal) {
         cout <<" Select Option from the List:" << endl;
         cout <<" 1. Print all student records 2.Add new records 3. Search student record by ID 4.Delete record by ID 5.Change name in the record 6.Find grades7.Quit ";
         int opt; cin >> opt;

        switch (opt) {
             case 1: {
                 for(i=0;i<count;i++)
                 {
                     cout<<"Student "<<i+1<<" details: "<<endl;
                     cout<<"Student ID: "<<stdn[i].ID<<endl;
                     cout<<"Student first name: "<<stdn[i].firstname<<endl;
                     cout<<"Student last name: "<<stdn[i].lastname<<endl;
                     cout<<"Student marks: "<<endl;
                     cout<<"quize marks: "
                     for(j=0;j<3;j++)
                      cout<<quiz[j]<<endl;
                     cout<<"exam marks: "<<endl;
                    for(j=0;j<3;j++)
                      cout<<exam[j]<<endl;
               
             }
                 break;
}
             case 2: {
                 cout << "Enter Student records: (enter -1 at end to stop adding)";
                 i=0;
                 while(1)
                 {
                  cout<<"Enter student firstname ";
                  cin>>stdn[i].firstname;
                   if(isdigit(firstname[0]))
                     break;
                   cout<<endl<<"Enter student lastname ";
                   cin>>stdn[i].lastname;
                   cout<<endl<<"Enter student ID ";
                   cin>>stdn[i].ID;
                   cout<<endl<<"Enter quizscore for student(only 3 marks) ";
                   for(j=0;j<3;j++)
                   {
                        cin>>stdn[i].quiz[j];
                    }
                   cout<<endl<<"Enter examscore for student(only 3 marks) ";
                    for(j=0;j<3;j++)
                   {
                        cin>>stdn[i].exam[j];
                    }
                    i++;
                   }
                   count=i;
                 break;
             }
             case 3: {
                 int search,flag=0;
                 cout<<"Enter ID you want to search: ";
                 cin>>search;
                 for(i=0;i<count;i++)
                 {
                   if(std[i].ID==search)
                     cout<<"record found";
                     flag=1;
                   }
                  if(flag==0)
                   cout<<"record not found ";
                  break;
             case 4: {
                 int del_ID;
                 cout<<"Enter ID you want to delete: ";
                 cin>>del_ID;
                 for(i=0;i<count;i++)
                 {
                   if(std[i].ID==search)
                   {
                    j=i+1;
                    
                   }
                }
               
                  while (j < count) {
                 stdn[j - 1] = stdn[j];
                  j++;
                 }
                 count--;

                     
                 break;
             }
        case 5:{
           char name[50],id;
           cout<<"Enter ID of stud whose name you want to change: ";
           cin>>id;
         for(i=0;i<count;i++)
         {
         
        if(std[i].ID==search)
                   {
                    j=i;
                    
                   }
                }
         cout<<"Enter new name you want to change: ";
         cin>>name;
         stdn[j].firstname=name;
      }
      case 6:
{
checkvalue=false;
break;
}
    }
}

Heres your code :
# include <iostream>
# include <stdlib.h>
# include <ctime>
# include <array>
# include <vector>
# include <string>

using namespace std;


class students {

public:
     void set_IDnum(string);
     void set_recd(int, string, string, vector<int> );
     void print_all_recd();
     void print_recd(int);
     void find_ID(int);
     void delete_ID(int);
     friend void change_name(int);

private:
     struct record {
         int IDnum;
         string first_name;
         string last_name;
         vector<int> prog;
     };   
     vector <record> student_records;
};


int main() {
     students stdn;

    string first_name, last_name;
     int IDnum;
     vector<int> prog;
     prog.resize(3);  
     srand((unsigned)time(NULL));
     for (int j = 0; j < 3; j++){
        prog[j] = rand() % 101;
     }
     cout << "Enter new records (ID first last):" << endl;
     for (int i = 0; i < 3; i++) {
         cout << " " << i+1 << " ";
         cin >> IDnum >> first_name >> last_name;

        // make new records
         stdn.set_recd(IDnum, first_name, last_name, prog);
     }
     bool checkVal = true;
     while(checkVal) {
         cout <<" Select Option from the List:" << endl;
         cout <<" 1. Print all student records 2. Search student record by ID 3.delete record by ID 4.Quit ";
         int opt; cin >> opt;

        switch (opt) {
             case 1: {
                 stdn.print_all_recd();
                 break;
             }
             case 2: {
                 cout << " Enter ID to search record: ";
                 int ID_search; cin >> ID_search;
                 stdn.find_ID(ID_search);
                 break;
             }
            
            case 3:
                {
                   cout<<" Enter ID you want to delete: ");
                  int ID1;
                  cin>>ID1;
                 stdn.delete_ID(ID1);
                 break;
             }
            case 4:
                  {
                    int x;
                    cout<<"Enter ID of the stud whose firstname you want to change";
                    cin>>x;
                    change_name(x);
                  }
            case 5: {
                 checkVal = false;
                 break;
             }
         }
     }
}


void students::set_recd(int IDnum, string first_name, string last_name, vector<int> prog) {
     record vector_element = {IDnum, first_name, last_name, prog};
     student_records.push_back(vector_element);
}

void students::set_IDnum(string first_name) {
     for (int i = 0; i < student_records.size(); i++) {
         if (student_records[i].first_name == first_name){
             cout << " Enter the new name: ";
             string new_fname;
             string new_lname;
             cin >> new_fname >> new_lname;
             student_records[i].first_name = new_fname;
             student_records[i].last_name = new_lname;
            
             return;
             //This is the change_name function but it doesnt work properly
         }
     }
}


void students::print_all_recd() {
     cout << endl;
     cout << " Student ID First Last" << endl;

    for (int i = 0; i < student_records.size(); i++) {
         cout << " " << i+1;
         cout << " " << student_records[i].IDnum << " " << student_records[i].first_name
         << " " << student_records[i].last_name << " " << endl;
     }
}

void students::print_recd(int recrd_num) {
     cout << " ID First Last" << endl;
     cout << " " << student_records[recrd_num].IDnum << " " << student_records[recrd_num].first_name
     << " " << student_records[recrd_num].last_name << " " << endl;
}

void students::find_ID(int IDnum) {
     bool flag = false; int num;
     for (int i = 0; i < student_records.size(); i++) {
         if (student_records[i].IDnum == IDnum) {
             print_recd(i);
             flag = true;
             num = i;    //will be used later to remove a student record based on ID number
         }
     }
     if (flag == false)
         cout << " No record found..." << endl;
}
void students::delete_ID(int IDnum) {
     bool flag = false; int num;
     for (int i = 0; i < student_records.size(); i++) {
         if (student_records[i].IDnum == IDnum) {
            
             flag = true;
             num = i;   
         }
     }

     if (flag == false)
     {
         cout << " No record found..." << endl;
         return;
      }
while (num < student_records.size()) {
                 stdn[num] = stdn[num+1];
                  num++;
                 }
                 student_records.resize(2);
}
void changename(int IDnum)
{
bool flag = false; int num; char name[30];
     for (int i = 0; i < student_records.size(); i++) {
         if (student_records[i].IDnum == IDnum) {
            
             flag = true;
             num = i;   
         }
     }

     if (flag == false)
     {
         cout << " No record found..." << endl;
         return;
      }
cout<<"Enter new name ";
cin>>student_record[i].first_name;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote