Coding in C++! WILL GIVE MULTIPLE POSITIVE RATES TO WHOEVER CAN CODE THIS PROGRA
ID: 3673738 • Letter: C
Question
Coding in C++!
WILL GIVE MULTIPLE POSITIVE RATES TO WHOEVER CAN CODE THIS PROGRAM.. I've done it before, and I will for anyone who works hard for this.
Thank you!
Write a program that stores a list of class objects named GradeBook by using vector, and allows users to add, remove or sort objects in the list by interactively giving commands until the user enters quit. The class GradeBook should contain three private data members:
The StudentlD should be unique in the list. Access to these private data members should be implemented through public member functions e.g. set member functions and get member functions. Please initialize the list with five GradeBook objects in it. Output the five commands' name at the beginning of your main function.
User's commands for input are:
add: Prompt the user to enter a new GradeBook object by giving StudentlD, StudentName and Grade. Check if the StudentID exists in the list, no duplicate of StudentID is allowed. Also check the Grade's range, which should be within [0.0, 100.0]. If input is valid add the object to the list and prepare for the next operation, if not continue to the next operation.
remove: Prompt the user to enter a StudentID, find the StudentID by using iterator. (which acts like pointer)
Example: vector<float>::iterator it = vec.begin() //vec is your vector
cout << *it << endl; //Print the value at index 0
it++;
cout << *it << endl; //Print the value at index 1
Then remove the corresponding object from the list. If StudentID doesn't exist, print out error message and continue to the next operation. When removing elements you will need to use the erase member function: http://en.cppreference.com/w/cpp/container/vector/erase
sort: Sort the list of class objects in ascending order by: StudentID or Grade. You should use stable sorting algorithm. (E.g. merge sort) Let the user to choose StudentID or Grade is used as reference for sorting, then sort the list of objects, after sorting please use print function to print the list. See sample for interaction.
print: Print the list, an object should be printed in an individual line with StudentlD, StudentName and Grade. Please print the column title at the beginning. (StudentlD StudentName Grade)
quit: exit the program
Sample input/output
5 commands are:
remove sort print quit
Please enter your command:
print
StudentID StudentName Grade
5 XXXXX 80.0
2 XXXXX 75.6
... ... ...
Please enter your command:
add
Please enter StudentID, StudentName and Grade:
2 XXYYX 60.3
StudentID already exists!
Should be able to run through all 5 commands..
Explanation / Answer
#include <vector>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
class StudentRecord
{
Private :
int id ;
char sname[20] ;
double grade ;
void add(void)
{
// vector container
vector <int> v1;
// iterator
vector <int>::iterator Iter1;
int i, j;
// total records of a students
printf("Enter the total number of record")
cin >> n;
// push student data in range , id starts from 0
for (i = 0; i <= n; i++)
{
v1.push_back(i);
}
void remove ()
{
cout << enter the student id to remove" << endl;
cin >> id1;
for (i = 0; i <= n; i++)
{
}
}
void sort ()
{
// do the sorting according to the student id
sort(v1.begin(), v1.end());
cout<<" Sorted v1 vector is: ";
for (Iter1 = v1.begin(); Iter1 != v1.end(); Iter1++)
cout<<*Iter1<<" ";
cout<<endl;
// to sort in descending order
sort(v1.begin(), v1.end(), greater<int>());
cout<<" Re-sorted (greater than) v1 vector is: ";
for (Iter1 = v1.begin(); Iter1 != v1.end(); Iter1++)
cout<<*Iter1<<" ";
cout<<endl;
}
void print()
{
// print the data
cout<<"Original v1 vector is: ";
for (Iter1 = v1.begin(); Iter1 != v1.end(); Iter1++)
cout<<*Iter1<<" ";
cout<<endl;
}
} ; // end of class definition
int main(void)
{
int choice ,
StudentRecord s1 ; // creating object
s1.add();
s1. remove();
s1.sort();
s1.print();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.