Question

In: Computer Science

C++ exercise ! Change the WEEK‐4 program to work through the GradeBook class. This program has...

C++ exercise ! Change the WEEK‐4 program to work through the GradeBook class.

This program has some functionality that you can use with the Gradebook class.

So, please revise Gradebook class so that the class can use sort() and display() functions of WEEK4 program .

week-4 program :

#include
#include
using namespace std;

void sort(char nm[][10]);
void display(char name[][10]);

int main() {
char names[10][10];
int i;
for (i=0; i<10; i++)
{

cout << "Enter name of the student : ";
cin >> names[i];
}
sort(names);

display(names);

return 0;
}

void sort(char nm[][10]){
char temp[10];
cout <<"Sorting names in Ascending Order " << endl;

for (int i = 0; i <10; ++i)
for (int j =i+1; j<10; j++)
{

if (strcmp(nm[i],nm[j])>0)
{

strcpy(temp,nm[i]);
strcpy(nm[i],nm[j]);
strcpy(nm[j],temp);
}
}

};
void display(char nm[][10]) {


cout <<"Displaying names in Ascending Order " << endl;

for (int i = 0; i <10; ++i)
{
cout<< nm[i] << " " <

}

}

--------------------------------------------------------------------------------

Gradebook class:

#include
#include // program uses C++ standard string class
using namespace std;

// GradeBook class definition
class GradeBook
{
public:

// function that sets the course name
void setCourseName( string name )
{
courseName = name; // store the course name in the object
} // end function setCourseName

// function that gets the course name
string getCourseName() const
{
return courseName; // return the object's courseName
} // end function getCourseName

// function that displays a welcome message
void displayMessage() const
{
// this statement calls getCourseName to get the
// name of the course this GradeBook represents
cout << "Welcome to the grade book for\n" << getCourseName() << "!"
<< endl;
} // end function displayMessage


private:
string courseName; // course name for this GradeBook
}; // end class GradeBook

// function main begins program execution
int main()
{
string nameOfCourse; // string of characters to store the course name
GradeBook myGradeBook; // create a GradeBook object named myGradeBook

// display initial value of courseName
cout << "Initial course name is: " << myGradeBook.getCourseName()
<< endl;

// prompt for, input and set course name
cout << "\nPlease enter the course name:" << endl;
getline( cin, nameOfCourse ); // read a course name with blanks
myGradeBook.setCourseName( nameOfCourse ); // set the course name

cout << endl; // outputs a blank line
myGradeBook.displayMessage(); // display message with new course name
} // end main

Solutions

Expert Solution

Thanks for the question.


Here is the completed code for this problem. Comments are included so that you understand whats going on. Let me know if you have any doubts or if you need anything to change.


Thank You !!


========================================================================================

#include <iostream>
#include <string>
using namespace std;

class GradeBook{
public:

void setCourseName( string name ){
courseName = name;
}
string getCourseName() const{
return courseName;
}
void displayMessage() const{
cout << "Welcome to the grade book for\n" << getCourseName() << "!"
<< endl;
}

// displays names of all the students in ascending order
void displayNames(){
   sortNames();
   cout <<"Displaying names in Ascending Order " << endl;
   for (int i = 0; i <10; ++i){
       cout<<"Student "<<i+1<<" is: "<< names[i] <<endl;
   }

}

// ask user for sstudent name and store the names in the array
void readNames(){
   for(int i=0; i<10;i++){
       cout<<"Enter student name: ";
       cin>>names[i];
   }
}


private:
string courseName;
string names[10]; // string array of size 10
// private sort function that sorts the names in the string array
void sortNames(){
       string temp;
       for (int i = 0; i <10; ++i)
           for (int j =i+1; j<10; j++)
           {
  
           if (names[i].compare(names[j])>0)
           {
  
               temp=names[i];
               names[i]=names[j];
               names[j]=temp;
           }
       }
}
};


int main(){
string nameOfCourse;
GradeBook myGradeBook;

cout << "Initial course name is: " << myGradeBook.getCourseName()<< endl;

cout << "\nPlease enter the course name:" << endl;
getline( cin, nameOfCourse );
myGradeBook.setCourseName( nameOfCourse );
cout << endl;
myGradeBook.displayMessage();
myGradeBook.readNames();
myGradeBook.displayNames();
}

===========================================================================================


Related Solutions

This is python: #Imagine you're writing a program to calculate the class #average from a gradebook....
This is python: #Imagine you're writing a program to calculate the class #average from a gradebook. The gradebook is a list of #instances of the Student object. # #You don't know everything that's inside the Student object, #but you know that it has a method called get_grade(). #get_grade() will return the average for the student #represented by a given instance of Student. # #You don't know if get_grade() is stored in memory or if #it's calculated when it's needed, but...
in c++ you need to write a program that maintains the gradebook for a specific course....
in c++ you need to write a program that maintains the gradebook for a specific course. For each student registered in this course, the program keeps track of the student’s name, identification number (id), four exam grades, and final grade. The program performs several functionalities such as: enrolling a student in the course, dropping a student from the course, uploading student’s exam grades, displaying the grades of a specific student, displaying the grades of all students in the course, and...
Week 3 In-Class Exercise C++ Payroll Design a PayRoll class that is an abstract data type...
Week 3 In-Class Exercise C++ Payroll Design a PayRoll class that is an abstract data type for payroll. It has data members for an employee’s hourly pay rate, number of hours worked, and total pay for the week. Your class must include the following member functions: a constructor to set the hours and pay rate as arguments, a default constructor to set data members to 0, member functions to set each of the member variables to values given as an...
C++ Program Overload the following operators to work with the Rational class and add test cases...
C++ Program Overload the following operators to work with the Rational class and add test cases in the driver program. Make sure your driver program now tests each of these symbols for your Rational Class. + – * / == != < <= > >= << (stream insertion operator, use the toString function) >> (stream extraction operator) Make sure you test all 12 operators Example Run (Bold is input), everything else is a print statement using the overloaded operators Enter...
(Language: c++)Write a program that displays a question and 4 possible answers numbered 1 through 4....
(Language: c++)Write a program that displays a question and 4 possible answers numbered 1 through 4. . The program should ask the user to answer 1, 2, 3, or 4 and tell them if they are correct or not. If the user enters anything besides 1, 2, 3, or 4 the program should return an error message example outout: whats 2+5? 1. 4 2. 7 3. 1 4. 0 // if user inputs anything other then option 2 the screen...
Create a working C# Program that will accept an input and has the following class. areaCircle...
Create a working C# Program that will accept an input and has the following class. areaCircle – computes the area of the circle volumeCube – computes the volume of a cube perimeterTraingle – computes the perimeter of a triangle surfaceAreaRect – computes the surface area of a rectangle *You may usePass by Value and/or Pass by Reference *Using ConsoleApp
Differentiate among the three phases of change that individuals must work through in process change.
Differentiate among the three phases of change that individuals must work through in process change.
Design a one-week corrective exercise program for a friend or client. Your program must include the...
Design a one-week corrective exercise program for a friend or client. Your program must include the following: Have your client fill out the Lower Extremity Functional Index and the Upper Extremity Functional Index. Summarize what the results tell you about your client (you do not need to submit the filled out forms). Conduct an Upper Body Multi-Joint Movement Assessment and a Lower Body Multi-Joint Movement Assessment on your client. Summarize your findings and how these findings influenced your program design....
Design a one-week corrective exercise program for a friend or client. Your program must include the...
Design a one-week corrective exercise program for a friend or client. Your program must include the following: Have your client fill out the Lower Extremity Functional Index and the Upper Extremity Functional Index. Summarize what the results tell you about your client (you do not need to submit the filled out forms). Conduct an Upper Body Multi-Joint Movement Assessment and a Lower Body Multi-Joint Movement Assessment on your client. Summarize your findings and how these findings influenced your program design....
C++ * Program 2:      Create a date class and Person Class.   Compose the date class...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class in the person class.    First, Create a date class.    Which has integer month, day and year    Each with getters and setters. Be sure that you validate the getter function inputs:     2 digit months - validate 1-12 for month     2 digit day - 1-3? max for day - be sure the min-max number of days is validate for specific month...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT