Question

In: Computer Science

create a C++ Program 1. Ask and get a course name 2. Create an array of...

create a C++ Program

1. Ask and get a course name

2. Create an array of students of size 10,

3. Initialize the elements of the students array of appropriate names and grades

4. Create an object of class GradeBook (provide the course name and the created student array, in 3 above, as arguments to the constructor call. The arguments are used to initialize the data members of the class GradeBook.

Desired Output:

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

Enter course name: Object Oriented Programming

=====================Entering Students' Information===============================

Enter the name and grade for 10 students

student # 1 name: John

Student # 1 grade : 100

student # 2 name: Mark

Student # 2 grade : 100

student # 3 name: Jesus

Student # 3 grade : 89

student # 4 name: Tony

Student # 4 grade : 87

student # 5 name: Leo

Student # 5 grade : 79

student # 6 name: Don

Student # 6 grade : 75

student # 7 name: Devin

Student # 7 grade : 83

student # 8 name: Xavier

Student # 8 grade : 90

student # 9 name: jerry

Student # 9 grade : 25

student # 10 name: Jones

Student # 10 grade : 46

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

Welcome to the grade book for

Object Oriented Programming!

=====================After Processing Class's Grade===============================

The grades are:

Jonh  : 100

Mark : 100

Jesus: 89

Tony : 87

Leo: 79

Don : 75

Devin: 83

Xavier : 90

Jerry : 25

Jones : 46

Class average is 77.40

Lowest grade is 25

Highest grade is 100

Grade distribution:

0-9:

10-19:

20-29: *

30-39:

40-49: *

50-59:

60-69:

70-79: **

80-89: ***

90-99: *

100: **

Press any key to continue . . .

SAMPLE CODE!!!!!!!!!!!!!!!!!!!!!!!!

GradeBook.h

#pragma once

#include<string>

#include<array>

class GradeBook {

public:

       GradeBook(std::string& cName,std::array<int,10>& sGrades) :

              courseName{ cName }, studentGrades{ sGrades } {

       }

       std::string getCourseName() const {

              return courseName;

       }

       void setCourseName(const std::string& cName) {

              courseName = cName;

       }

       void processGrades() const {

              outputGrades();

              std::cout << "\nClass average: " << getAverage() << std::endl;

              std::cout << "\nClass maximum: " << getMaximum() << std::endl;

              std::cout << "\nClass minimum: " << getMinimum() << std::endl;

              std::cout << "Bar Chart:\n";

              outputBarChart();

       }

       int getMaximum() const {

              int highGrade{ 0 };

              //range-based for loop

              for (int grade : studentGrades) {

                     if (highGrade < grade) {

                            highGrade = grade;

                     }

              }

              return highGrade;

       }

       int getMinimum() const {

              int lowGrade{ 100 };

              for (int grade : studentGrades) {

                     if (lowGrade > grade) {

                            lowGrade = grade;

                     }

              }

              return lowGrade;

       }

       double getAverage() const {

              int sum{ 0 };

              for (int grade : studentGrades) {

                     sum += grade;

              }

              return static_cast<double>(sum) / studentGrades.size();

       }

       void outputGrades() const {

              std::cout << "\n The grades are: \n\n";

              for (size_t i{ 0 }; i < studentGrades.size(); ++i)

              {

                     std::cout <<"Student "<< i + 1 << " grade: " << studentGrades.at(i) << std::endl;

              }

       }

       void outputBarChart() const {

              std::cout << "\nGrade distribution:\n";

              std::array<int, 11> frequency{};

              for (int grade : studentGrades) {

                     ++frequency[grade / 10];

              }

              for (size_t i{ 0 }; i < frequency.size(); ++i)

              {

                     if (i == 0) {

                            std::cout << "  0-9:";

                     }

                     else if (i == 10) {

                            std::cout << "  100:";

                     }

                     else {

                                   std::cout << i * 10 << "-" << (i*10) + 9 << ":";

                     }

                     for (unsigned stars{ 0 }; stars < frequency[i]; ++stars) {

                            std::cout << '*';

                     }

                     std::cout << std::endl;

                     

              }

       }

private:

       std::string courseName;

       std::array<int, 10> studentGrades;

};

GradeBookDriver.cpp

#include<iostream>

#include<string>

#include"GradeBook.h"

#include<array>

using namespace std;

int main()

{

       string courseName = "COSC 1337 Object Oriented Programming";

       array<int, 10> studentGrades{ 87, 68, 94, 100, 83, 78, 85, 91, 76, 87 };

       GradeBook myGradeBook(courseName,studentGrades);

       myGradeBook.setCourseName(courseName);

       myGradeBook.processGrades();

}

Solutions

Expert Solution

GradeBookDriver.cpp

#include<bits/stdc++.h>
#include "GradeBook.h"
using namespace std;
int main()
{
        
        array<pair<string,int>,10> a;
        string courseName;
        cout<<"Enter CourseName\t";
        cin>>courseName;
        cout<<"\n Enter the name and grade for 10 students\n";
        string x;
        int y;
        for(int i=0;i<10;i++)
        {
                cin>>x>>y;
                a[i]={x,y};
        }
        
        GradeBook g(courseName,a);
        g.processGrades();
}

GradeBook.h

#include<bits/stdc++.h>
using namespace std;
class GradeBook{
        private:
                string courseName;
                array<pair<string,int>,10> studentGrades;
        public:
                
                GradeBook(string Cname,array<pair<string,int>,10> &a)
                {
                        courseName=Cname;
                        studentGrades=a;
                }
                
                std::string getCourseName() const {

              return courseName;

       }

       void setCourseName(const std::string& cName) {

              courseName = cName;

       }

       void processGrades() const {

              outputGrades();

              std::cout << "\nClass average: " << getAverage() << std::endl;

              std::cout << "\nClass maximum: " << getMaximum() << std::endl;

              std::cout << "\nClass minimum: " << getMinimum() << std::endl;

              std::cout << "Bar Chart:\n";

              outputBarChart();

       }

       int getMaximum() const {

              int highGrade= 0;

              //range-based for loop

              for (auto grade : studentGrades) {

                     if (highGrade < grade.second) {

                            highGrade = grade.second;

                     }

              }

              return highGrade;

       }

       int getMinimum() const {

              int lowGrade=100;

              for (auto grade : studentGrades) {

                     if (lowGrade > grade.second) {

                            lowGrade = grade.second;

                     }

              }

              return lowGrade;

       }

       double getAverage() const {

              int sum=0;

              for (auto grade : studentGrades) {

                     sum += grade.second;

              }

              return static_cast<double>(sum) / studentGrades.size();

       }

       void outputGrades() const {

              std::cout << "\n The grades are: \n\n";

              for(int i=0;i<studentGrades.size();i++)
              {
                cout<<"student #" <<i+1<<"name: "<<studentGrades[i].first<<endl;
                cout<<"student #" <<i+1<<"grade: "<<studentGrades[i].second<<endl;
                          }

       }

       void outputBarChart() const {

              std::cout << "\nGrade distribution:\n";

              std::array<int, 11> frequency{};

              for (auto grade : studentGrades) {

                     ++frequency[grade.second / 10];

              }

              for (int i{ 0 }; i < frequency.size(); ++i)

              {

                     if (i == 0) {

                            std::cout << "  0-9:";

                     }

                     else if (i == 10) {

                            std::cout << "  100:";

                     }

                     else {

                                   std::cout << i * 10 << "-" << (i*10) + 9 << ":";

                     }

                     for (unsigned stars{ 0 }; stars < frequency[i]; ++stars) {

                            std::cout << '*';

                     }

                     std::cout << std::endl;

                     

              }

       }
};

Just make array of pair of string and int instead of normally pair.


Related Solutions

Write C++ program to do the following: 1. Create integer array size of 10 2. Ask...
Write C++ program to do the following: 1. Create integer array size of 10 2. Ask user input the values of the array's element using for loop 3. pass the array to void function. in void function do the following: a. Find the maximum of the array. b. Compute the element average c. Find out how many numbers are above the average d. Find out and print how many numbers are below the average e. find out how many numbers...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
Write a program in c++ to do the following: 2. Create an array to hold up...
Write a program in c++ to do the following: 2. Create an array to hold up to 20 integers. 3. Create a data file or download attached text file (twenty_numbers.txt) that contains UP TO 20 integers. 4. Request the input and output file names from the user. Open the files being sure to check the file state. 5. Request from the user HOW MANY numbers to read from the data file, up to twenty. Request the number until the user...
create a python program that ask for a name and birth year separated by a comma....
create a python program that ask for a name and birth year separated by a comma. the program should keep prompting until the user inputs 'quit'. print the dictionary containing the key value pair name:year in the same order they were inputted. print the name and birth year on a single line for each of the entries. finally print the dictionary with the key value paris swapped and sorted by birth year. from youngest to oldeest.
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
Please code in c# (C-Sharp) Write a program that will ask the user for their name....
Please code in c# (C-Sharp) Write a program that will ask the user for their name. If the user does not input anything, display a warning before continuing. The program will then ask the user whether they want to have an addition, subtraction, multiplication, or division problem. Once the user indicates their choice, the program will display 2 randomly generated numbers from 1 to 9 in a math problem matching the user’s choice. Example: user selects addition, the equation presented...
C++ Write a program to declare an array of double of size 25, ask the user...
C++ Write a program to declare an array of double of size 25, ask the user to input all array elements from the keyboard, then write a function named out_of_order that will test this array for the condition a[0] >= a[1] >= a[2] >= ... > a[24] The function returns a -1 if the elements are not out of order, otherwise it returns the index of the first element that is out of order. Explain what you do to avoid...
c++ In this program ask the user what name they prefer for their file, and make...
c++ In this program ask the user what name they prefer for their file, and make a file, the file name should za file. Get a number from the user and save it into the create file. should be more than 20 number in any order. print out all 20 numbers in a sorted array by using for loop, last print out its total and average. At last create a function in which you will call it from main and...
10) Create a java program that will ask for name and age with method age where...
10) Create a java program that will ask for name and age with method age where it will check the condition that id you are greater than 18 you can vote.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT