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...
Week 4 Assignment: What’s in a Number? Directions: You are to write a C++ program that...
Week 4 Assignment: What’s in a Number? Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: Your C++ source code file. (The file with the .CPP extension).No other files will be accepted. A screenshot of your program running. Program Instructions: To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to...
You work for a bank that has a program with a dependency of the account class....
You work for a bank that has a program with a dependency of the account class. Unfortunately the hard drive that contained the source code for the account class went bad and no backup can be found. Obviously, this means you bank needs to address this issue. However, your task is to recreate the account class. The good news is that your company was able to locate a tester of the account class and one helper function to output the...
Create a C++ program to simulate an art gallery: 4 classes: Gallery class Has three vectors...
Create a C++ program to simulate an art gallery: 4 classes: Gallery class Has three vectors of type Painting which represent three categories of paintings (abstract, impressionism, pointillism) Has a function that reads in paintings from a file and stores each painting in the correct vector Read in paintings from file (will have multiple paintings) Title of painting Artists first name Artists last name Address street number Address street name Address city Address state Address zip Artists website Category Number...
**** In C++ ****Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4...
**** In C++ ****Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax(int[] arr) returns the maximum value in the an array int arrayMin(int[] arr) returns the minimum value in an array void arraySquared(int[] arr) changes every value in the array to its square (value²) void arrayReverse(int[] arr) reverses the array (for example: array storing 7 8 9 becomes 9 8 7 ) The program main method creates a single-dimensional array of...
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...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT