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

In this lab assignment, use class to create the data structure of student record

ID: 3677548 • Letter: I

Question

In this lab assignment, use class to create the data structure of student records. Each record contain RUID, student name, quiz grades, and exam grades. The data structure should be declared as below. All member data of the class are declared as private data.

class students {

public:

// all necessary member functions here;

// using the friend function in class

friend void change_name() // passing necessary inputs

private:

struct record {

int RUID;

string first_name;

string last_name;

vector quiz_grades;

array exam_grafes;

};

vector student_records;

};

In this assignment, we also introduce the friend function of the class. A function can be declared as friend of the class as seen as above. A friend function is not a member function of the class. However, it has access to the private data of the class. To call the friend function in the main() function:

int main() {

students stdn;

change_name ( stdn, );

}

The program should work as follow,

Starting the program, the menu displayed as follow and wait for user input

Welcome to class list!

Select the following options (-1 to quit):

1. Print current list.

2. Add new records to the list.

3. Find record by RUID (binary search).

4. Delete record by RUID.

5. Change name in the record (using FRIEND function).

Option 1: Print the list of the current records. If the list is empty, prompt the user to input new student records by entering first name and last name, the RUID and grades should be generated using appropriate random numbers. (RUIDs should be 4-digit numbers). (1 to finish making new record and display the list).

Option 2: Add new record to the list by entering first name and last name. (-1 to finish and display the list).

Option 3: Search for a student record using RUID and display if record found. Display appropriate message if not found RUID.

Option 4: Delete a record using RUID. Display appropriate message if not found RUID.

Option 5: Change the name in the record using friend function. Use RUID to search for the record.

When inputting the names for the new records, enter -1 to exit making new records and display the list. Use try/catch to catch the error of input of -1 to string first_name or last_name variable and prevent your program from crashing.

Write a header file for class definition, a cpp file for the functions of the class, and a main.cpp file. Submit all 3 files for this assignment.

Look in the following sample out for the guideline of your program. The program quit on -1 input.

Welcome to class list!

Select the following options (-1 to quit):

1. Print current list.

2. Add new records to the list.

3. Find record by RUID (binary search).

4. Delete record by RUID.

5. Change name in the record (using FRIEND function). 1

The student list is empty. Enter new student record (-1 to quit)

Student 1 first name: Mary

Student 1 last name: Jane

Student 2 first name: James

Student 2 last name: Page

Student 3 first name: Michael

Student 3 last name: -1

Student RUID First Name Last Name Quiz Score Exam Score

1 8003 Mary Jane 72 47 83 44 35 61

2 4247 James Page 52 88 61 13 69 87

Select the following options (-1 to quit):

1. Print current list.

2. Add new records to the list.

3. Find record by RUID (binary search).

4. Delete record by RUID.

5. Change name in the record (using FRIEND function). 2

Student 3 first name: Michael

Student 3 last name: Lang

Student 4 first name: -1

Student RUID First Name Last Name Quiz Score Exam Score

1 8003 Mary Jane 72 47 83 44 35 61

2 4247 James Page 52 88 61 13 69 87

3 5398 Michael Lang 26 43 79 25 6 78

Select the following options (-1 to quit):

1. Print current list.

2. Add new records to the list.

3. Find record by RUID (binary search).

4. Delete record by RUID.

5. Change name in the record (using FRIEND function). 3

Enter the RUID for searching (4-digit number): 5398

Found the following record:

RUID First Name Last Name Quiz Score Exam Score

5398 Michael Lang 26 43 79 25 6 78

Select the following options (-1 to quit):

1. Print current list.

2. Add new records to the list.

3. Find record by RUID (binary search).

4. Delete record by RUID.

5. Change name in the record (using FRIEND function). 4

Enter the RUID for deleting (4-digit number): 4247

Student RUID First Name Last Name Quiz Score Exam Score

1 5398 Michael Lang 26 43 79 25 6 78

2 8003 Mary Jane 72 47 83 44 35 61

Note that the record is sorted by RUID after the searching.

Select the following options (-1 to quit):

1. Print current list.

2. Add new records to the list.

3. Find record by RUID (binary search).

4. Delete record by RUID.

5. Change name in the record (using FRIEND function). 5

Enter the RUID for chaging name: 8003

Enter new first name: Jenny

Enter new Last name: Smith

RUID First Name Last Name Quiz Score Exam Score

8003 Jenny Smith 72 47 83 44 35 61

Select the following options (-1 to quit):

1. Print current list.

2. Add new records to the list.

3. Find record by RUID (binary search).

4. Delete record by RUID. 5. Change name in the record (using FRIEND function). -1

Explanation / Answer

Comments added

#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
using namespace std;
class students {
public:
// all necessary member functions here;
// using the friend function in class
friend void change_name(int ruid, string name); // passing necessary inputs
void printRecords(void);
void newRecord(string first, string last);
int search(int ruid);
void deleteRecord(int ruid);

private:
struct record {
int RUID;
string first_name;
string last_name;
std::vector<double> quiz_grades;
double exam_grades[3];
};
std::vector<record> student_records;

//printng stored records
void students:: printRecords(void)
{
for (int i = student_records.begin(); i < student_records.end(); i++) {
//printing ruid and names
cout << "RUID: " << student_records[i].RUID << " First Name: " << student_records[i].RUID.first_name << " Last Name: " << student_records[i].RUID.last_name;
cout << " Quiz Grades: ";
//printing quiz grades
for (int j = student_records[i].quiz_grades.begin(); j < student_records[i].quiz_grades.end(); j++) {
cout << student_records[i].quiz_grades[j] << " ";
}
//printng exam grades
cout << " Exam Grades: ";
for (int j = 0; j < 3; j++) {
cout << student_records[i].exam_grades[j] << " ";
}
}
}

//adding new record
students::void newRecord(string first, string last)
{
struct record newStudent;
newStudent.first_name = first;
newStudent.last_name = last;
//adding random ruid number
int ruid = rand() % 1000 + 1000;
newStudent.RUID = ruid;

//now quiz grades
vector<double> quiz;
for (int i = 0; i < 3; i++) {
double num = rand() % 100;
quiz.push_back(num);
}
//now exam grades
double grades[3];
for (int i = 0; i < 3; i++) {
double num = rand() % 100;
grades[i] = num;
}
newStudent.quiz_grades = quiz;
newStudent.exam_grades = grades;

//finally storing this record into records of vector
student_records.push_back(newStudent);
}
//searcing by ruid
students::int search(int ruid)
{
int found = 0;
for (int i = student_records.begin(); i < student_records.end(); i++) {
if (student_records[i].ruid == ruid) {
cout << " Found";
cout << " Name: " << student_records[i].first_name << " " << student_records[i]..last_name;
found = 1;
return i;
}
}
if (found == 0) {
cout << " Sorry not found.";
}
return -1;
}
//deleting by ruid
students::void deleteRecord(int ruid)
{
int index = search(ruid);
if (index != -1) {
//removing record
student_records.erase(student_records.begin() + index);
}
else {
cout << "Not found";
}
}

// changing name
friend void change_name(int ruid, string name)
{
int index = search(ruid);
if (index != -1) {
student_records.first_name = name;
}
}
};
int main()
{
students stdn;
while (true) {
//displaying menu
cout << "Welcome to class list! Select the following options (-1 to quit): 1. Print current list. 2. Add new records to the list. 3. Find record by RUID (binary search). 4. Delete record by RUID. 5. Change name in the record (using FRIEND function).";
int choice;
cin >> choice;

if (choice == 1) {
stdn.printRecords();
}
else if (choice == 2) {
string firstname, lastname;
cout << " Enter first name: ";
cin >> firstname;
cout << " Enter last name: ";
cin >> lastname;
stdn.newRecord(firstname, lastname);
}
else if (choice == 3) {
cout << " Enter RUID for search: ";
int ruid;
cin >> ruid;
stdn.search(int ruid);
}
else if (choice == 3) {
cout << " Enter RUID for delete: ";
int ruid;
cin >> ruid;
stdn.deleteRecord(int ruid);
}
else if (choice == 4) {
cout << " Enter RUID for change: ";
int ruid;
cin >> ruid;
string name;
cout << "Enter name to change: ";
cin >> name;
stdn.change_name(int ruid, string name);
}
else { //exiting from app

cout << " Program Terminated";
break;
}
}
}

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