Question

Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...

Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers.

Directions:

Using the following parallel array and array of vectors:

// may be declared outside the main function
const int NUM_STUDENTS = 3; 
// may only be declared within the main function

string students[NUM_STUDENTS] = {"Tom","Jane","Jo"};
vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}};

Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp

Write a C++ program to run a menu-driven program with the following choices:

1) Display the grades
2) Add assignment grade
3) Quit

Make sure your program conforms to the following requirements:
1. This program should be called HelpWithGradesPtr.cpp

Include the basic header in your program. (5 points deduction if missing)

2.You must rewrite the following functions from the Help With Grading Program to only accept parameters that are either constant pointers or pointers; all functionality in the original program must remain intact :

  • displayGrades
  • addGrades (25 points)

3. Add comments wherever necessary. (5 points)

HERE IS MY CODE.
I need to rewrite my current functions to take in pointers though.

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

//Function prototypes
int getValidGrade();
void DisplayMenuOptions();
int SelectValidMenuChoice();
void displayGrades(string students[],vector<int> grades[]);
void addGrades(string students[],vector<int> g[]);


const int NUM_STUDENTS = 3; // Number of students for program
const int NUM_GRADES = 5; // Number of assignments per student

int main()
{
    string students[NUM_STUDENTS] = {"Tom","Jane","Jo"};
    vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}};

    //Welcome message to welcome user to program
    cout << "Welcome to the Help With Grades program.." << endl;

    //Loop program until user chooses to quit program
    int MenuChoice = 0;

    do {
        //Called based upon user menu selection
        switch(MenuChoice)
        {
            case 1:
                displayGrades(students, grades);
                break;
            case 2:
                addGrades(students, grades);
                break;
        }
        // Get menu choice from user
        MenuChoice = SelectValidMenuChoice();
    }while (MenuChoice !=3);
    return 0;

}

//*****************************************************************
// Definition of function getValidGrade which validates grade     *
// entered by user                                                *
//*****************************************************************
int getValidGrade()
{
    int valid_grade;
    do{
        cin >> valid_grade;
        if (valid_grade < 0 || valid_grade > 100)
            cout << "Please enter a valid grade.." << endl;
    }while(valid_grade < 0 || valid_grade > 100);
    return valid_grade;
}


//*****************************************************************
// Definition of function DisplayMenuOptions which displays menu  *
// options for user to choose from                                *
//*****************************************************************
void DisplayMenuOptions()
{
    cout << "1) Display the grades " << endl;
    cout << "2) Add assignment grade " << endl;
    cout << "3) Quit " << endl;
}

//*****************************************************************
// Definition of function SelectValidMenuChoice which allows user *
// to enter a menu selection and validates the entry              *
//*****************************************************************
int SelectValidMenuChoice()
{
    int MenuChoice;
    // Get menu selection from user
    DisplayMenuOptions();
    cout << "Enter in your menu choice: " << endl;
    cin >> MenuChoice;
    while ((MenuChoice <=0) || (MenuChoice >3)) // input validation loop
    {
        // Get menu selection from user
        DisplayMenuOptions();
        cout << "Enter in your menu choice: " << endl;
        cin >> MenuChoice;
    }
    return MenuChoice;
}

//*****************************************************************
// Definition of function DisplayGrades which displays grades     *
// for each student for current assignments                       *
//*****************************************************************
void displayGrades(string students[],vector<int> grades[])
{
    cout<<"Name Assign.1 Assign.2 Assign.3 Assign.4 Assign.5"<<endl;
    for(int i=0;i<NUM_STUDENTS;i++){
        cout<<students[i]<<" ";
        for(int j=0;j<NUM_GRADES;j++){
            cout<<grades[i][j]<<" ";
        }
        cout<<endl;
    }
}
//*****************************************************************
// Definition of function AddAssignmentGrade which allows user    *
// to enter in a new assignment grade for student                 *
//*****************************************************************
void addGrades(string students[],vector<int> grades[])
{
    for(int i=0;i<NUM_STUDENTS;i++){
        cout<< "Student " << students[i] << ": Please enter in the grade... " <<endl;
        for(int j=0;j<1;j++){
            grades[i].push_back(getValidGrade());
        }
    }

}

Homework Answers

Answer #1


Hey, the notation [] itself implies that the parameter is of type pointer. All your parameters are already using the notation []. Anyway I changed the notations to expicitely to pointers and attached the modified code. If you need assistant for anything else or you get any queries, feel free to comment.

Program Screenshot for Indentation Reference:

Sample Output:

Program code to copy:

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

//Function prototypes
int getValidGrade();
void DisplayMenuOptions();
int SelectValidMenuChoice();
void displayGrades(const string* students,const vector<int>* grades);
void addGrades(const string* students,vector<int>* grades);


const int NUM_STUDENTS = 3; // Number of students for program
const int NUM_GRADES = 5; // Number of assignments per student

int main()
{
    string students[NUM_STUDENTS] = {"Tom","Jane","Jo"};
    vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}};

    //Welcome message to welcome user to program
    cout << "Welcome to the Help With Grades program.." << endl;

    //Loop program until user chooses to quit program
    int MenuChoice = 0;

    do {
        //Called based upon user menu selection
        switch(MenuChoice)
        {
            case 1:
                displayGrades(students, grades);
                break;
            case 2:
                addGrades(students, grades);
                break;
        }
        // Get menu choice from user
        MenuChoice = SelectValidMenuChoice();
    }while (MenuChoice !=3);
    return 0;

}

//*****************************************************************
// Definition of function getValidGrade which validates grade     *
// entered by user                                                *
//*****************************************************************
int getValidGrade()
{
    int valid_grade;
    do{
        cin >> valid_grade;
        if (valid_grade < 0 || valid_grade > 100)
            cout << "Please enter a valid grade.." << endl;
    }while(valid_grade < 0 || valid_grade > 100);
    return valid_grade;
}


//*****************************************************************
// Definition of function DisplayMenuOptions which displays menu *
// options for user to choose from                                *
//*****************************************************************
void DisplayMenuOptions()
{
    cout << "1) Display the grades " << endl;
    cout << "2) Add assignment grade " << endl;
    cout << "3) Quit " << endl;
}

//*****************************************************************
// Definition of function SelectValidMenuChoice which allows user *
// to enter a menu selection and validates the entry              *
//*****************************************************************
int SelectValidMenuChoice()
{
    int MenuChoice;
    // Get menu selection from user
    DisplayMenuOptions();
    cout << "Enter in your menu choice: " << endl;
    cin >> MenuChoice;
    while ((MenuChoice <=0) || (MenuChoice >3)) // input validation loop
    {
        // Get menu selection from user
        DisplayMenuOptions();
        cout << "Enter in your menu choice: " << endl;
        cin >> MenuChoice;
    }
    return MenuChoice;
}

//*****************************************************************
// Definition of function DisplayGrades which displays grades     *
// for each student for current assignments                       *
//*****************************************************************
void displayGrades(const string* students,const vector<int>* grades)
{
    cout<<"Name Assign.1 Assign.2 Assign.3 Assign.4 Assign.5"<<endl;
    for(int i=0;i<NUM_STUDENTS;i++){
        cout<<students[i]<<" ";
        for(int j=0;j<NUM_GRADES;j++){
            cout<<grades[i][j]<<" ";
        }
        cout<<endl;
    }
}
//*****************************************************************
// Definition of function AddAssignmentGrade which allows user    *
// to enter in a new assignment grade for student                 *
//*****************************************************************
void addGrades(const string* students,vector<int>* grades)
{
    for(int i=0;i<NUM_STUDENTS;i++){
        cout<< "Student " << students[i] << ": Please enter in the grade... " <<endl;
        for(int j=0;j<1;j++){
            grades[i].push_back(getValidGrade());
        }
    }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream>...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream> using namespace std; void shownumbers(int, int); int main() { int x, y; cout << "Enter first number : "; cin >> x; cout << "Enter second number : "; cin >> y; shownumbers(x, y); return 0; } void shownumbers(int a, int b) { bool flag; for (int i = a + 1; i <= b; i++) { flag = false; for (int j =...
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double secondQuizz; double midTerm; double finalTerm; string name; }; int main() { int n; cout<<"enter the number of students"<<endl; cin>>n; struct student students[n]; int i; struct student istudent; for(i=0;i<n;i++) {    cout<<"Student name?"; cin >> istudent.name; cout<<"enter marks in first quizz , second quizz , mid term , final term of student "<<i+1<<endl; cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm; } for(i=0;i<n;i++) { double marks=0; double score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm; marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50); double totalArrgegateMarks =...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
In this assignment, you’ll make an inventory system for a store’s items, including produce and books....
In this assignment, you’ll make an inventory system for a store’s items, including produce and books. The starter program is an inventory system for only produce. 1. Include the price of an item by adding to the Item class the protected data member int priceInDollars that stores the price in dollars of an individual item. Write a public function SetPrice with a single int parameter prcInDllrs and returns nothing. SetPrice assigns the value of prcInDllrs to priceInDollars. Modify the AddItemToInventory...
Please use this template. In this exercise you are to use a vector to store integers...
Please use this template. In this exercise you are to use a vector to store integers entered by the user. Once you have filled the vector, ask the user for a value to search for. If found, remove the value from the vector, keeping all other values in the same relative order, and then display the remaining values. #include <iostream> #include <vector> #include <climits> using namespace std; //Fills vector with user input until user enters 0 (does not include 0...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...