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
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
The following program allows the user to enter the grades of 10 students in a class...
The following program allows the user to enter the grades of 10 students in a class in an array called grade. In a separate loop, you need to test if a grade is passing or failing, and copy the grade to an array to store passing or failing grades accordingly. A passing grade is a grade greater than or equal to 60. You can assume the use will enter a grade in the range of 0 to 100, inclusive. ...
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 =...
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 =...
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...
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();...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT