Question

How could I separate the following code to where I have a gradebook.cpp and gradebook.h file?...

How could I separate the following code to where I have a gradebook.cpp and gradebook.h file?

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

class Gradebook {

public :
int homework[5] = {-1, -1, -1, -1, -1};
int quiz[5] = {-1, -1, -1, -1, -1};
int exam[3] = {-1, -1, -1};
string name;

int printMenu() {
int selection;
cout << "-=| MAIN MENU |=-" << endl;
cout << "1. Add a student" << endl;
cout << "2. Remove a student" << endl;
cout << "3. Change a student's grade" << endl;
cout << "4. Change group weights" << endl;
cout << "5. Change the gradebook name" << endl;
cout << "6. Display class averages" << endl;
cout << "7. Display full report" << endl;
cout << "0. QUIT\n" << endl;
cout << "Enter an action: ";
cin >> selection;
cout << endl;
return selection;
}

string addStudent() {
string firstName, lastName, stuName;
cout << "-=| ADDING STUDENT |=-" << endl;
cout << "Please enter the student's name (first and last name): ";
cin >> firstName >> lastName;
firstName[0] = toupper(firstName[0]);
lastName[0] = toupper(lastName[0]);
stuName = firstName + " " + lastName;
return stuName;
}

int changeGrade() {
int num;
cout << "-=| CHANGING GRADE |=-" << endl;
cout << "1. Change a homework grade" << endl;
cout << "2. Change a quiz grade" << endl;
cout << "3. Change a exam grade\n" << endl;
cout << "What type of grade would you like to change: ";
cin >> num;
return num;
}

};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

First of all remember that ".h" file and ".cpp" file are called the Header file and the C++ File respectively.

Now, the Header file(.h file) are there for declaration while the .cpp file are there for the Implementation

Here are the separate .h and .cpp file from the code given :-

1. gradebook.h file :

#ifndef _gradebook_H
#define _gradebook_H

#include <iostream>
#include <stdio.h>
#include <string>

class Gradebook {

public :
int homework[5] = {-1, -1, -1, -1, -1};
int quiz[5] = {-1, -1, -1, -1, -1};
int exam[3] = {-1, -1, -1};
string name;

int printMenu();

string addStudent();

int changeGrade();

};
#endif

2. gradebook.cpp file :

#include <gradebook.h>

using namespace std;

int Gradebook::printMenu() {
int selection;
cout << "-=| MAIN MENU |=-" << endl;
cout << "1. Add a student" << endl;
cout << "2. Remove a student" << endl;
cout << "3. Change a student's grade" << endl;
cout << "4. Change group weights" << endl;
cout << "5. Change the gradebook name" << endl;
cout << "6. Display class averages" << endl;
cout << "7. Display full report" << endl;
cout << "0. QUIT\n" << endl;
cout << "Enter an action: ";
cin >> selection;
cout << endl;
return selection;
}

string Gradebook::addStudent() {
string firstName, lastName, stuName;
cout << "-=| ADDING STUDENT |=-" << endl;
cout << "Please enter the student's name (first and last name): ";
cin >> firstName >> lastName;
firstName[0] = toupper(firstName[0]);
lastName[0] = toupper(lastName[0]);
stuName = firstName + " " + lastName;
return stuName;
}

int Gradebook::changeGrade() {
int num;
cout << "-=| CHANGING GRADE |=-" << endl;
cout << "1. Change a homework grade" << endl;
cout << "2. Change a quiz grade" << endl;
cout << "3. Change a exam grade\n" << endl;
cout << "What type of grade would you like to change: ";
cin >> num;
return num;
}

I hope that answer helped if it was helpful please do give a like and comment if any further help is required.

Thank you!

Add a comment
Know the answer?
Add Answer to:
How could I separate the following code to where I have a gradebook.cpp and gradebook.h file?...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • Here is the code from the previous three steps: #include <iostream> using namespace std; class Student...

    Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...

  • I need to be able to input first and last name. My code only outputs first...

    I need to be able to input first and last name. My code only outputs first when you put 2 names. This is not my full code. Any type of help wou;d be great! int main() { int main_choice; int grade_choice; int std_id; int new_grade; char g_name[100]; char s_name[100]; float a,b,c; gradebook g; do { cout <<endl; cout<< " -=| MAIN MENU |=-" << endl; cout<< "1. Add a student" << endl; cout << "2. Remove a student" << endl;...

  • Rework this project to include a class. As explained in class, your project should have its...

    Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...

  • "Function does not take 0 arguments". I keep getting this error for my last line of...

    "Function does not take 0 arguments". I keep getting this error for my last line of code: cout << "First Name: " << employee1.getfirstName() << endl; I do not understand why. I am trying to put the name "Mike" into the firstName string. Why is my constructor not working? In main it should be set to string firstName, string lastName, int salary. Yet nothing is being put into the string. #include<iostream> #include<string> using namespace std; class Employee {    int...

  • (Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the...

    (Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the date of birth.            **fall.sort(compare_DOB); //Here lies your error** #include <fstream> #include <iostream> #include <string> #include <list> #include <cctype> using namespace std; const char THIS_TERM[] = "fall.txt"; const string HEADER = "\nWhat do you want to do ?\n\n" "\t. Add a new friend name and DOB ? \n" "\t. Edit/Erase a friend record ? \n" "\t. Sort a Friend's record ? \n"...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

  • I need to get this two last parts of my project done by tonight. If you...

    I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT