Question

C++ help : Write a class Person with an Attribute for Name. Write a Student class...

C++ help :

Write a class Person with an Attribute for Name. Write a Student class that extends Person and has an attribute for NumberOfCreditsEarned and NumberOfCreditsRequiredToGraduate. Add a function Print() to Student that displays their name and the number of credits they still have to complete before graduating.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

class Person {
private:
   string Name;
public:
   Person(string n) {
      Name = n;
   }
   string getName() {
      return Name;
   }
};

class Student : public Person {
private:
   int NumberOfCreditsEarned;
   int NumberOfCreditsRequiredToGraduate;
public:
   Student(string n, int earned, int required) : Person(n) {
      NumberOfCreditsEarned = earned;
      NumberOfCreditsRequiredToGraduate = required;
   }
   void Print() {
      cout << getName() << " requires " << (NumberOfCreditsRequiredToGraduate-NumberOfCreditsEarned) << " more credits to complete the graduation" << endl;
   }
};

int main() {
   Student s("your name", 56, 100);
   s.Print();
   return 0;
}

Let me know if you need me to make any changes

Add a comment
Know the answer?
Add Answer to:
C++ help : Write a class Person with an Attribute for Name. Write a Student class...
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
  • Person Height in Person is also a class In order to fill in the Height attribute,...

    Person Height in Person is also a class In order to fill in the Height attribute, a Height object needs to be created . int number * String name . String position .Height height App int weight String hometowrn Creates one FootballPlayer object Use the method getlnfo() to display the FootballPlayer's complete information String highSchool Height int feet int inches . String getlnfo() extends String getlnfo() FootballPlayer int number String position . FootballPlayer is a Person with two extra attributes...

  • *** C++ *** Create a class called Student that contains a first name ( string) and...

    *** C++ *** Create a class called Student that contains a first name ( string) and an student id number (type long).     1. Include a member function called get_data( ) to get data from the user for insertion into the object,     2. Also include a function called display_data( ) that displays the student data. Then write a complete program that uses the class to do some computation. Your main function, main( ), should create a Dynamic Array of...

  • Please use C++,thank you! Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, o...

    Please use C++,thank you! Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, or search for a Perso n object in the address book The add method should add a person object to the address book. The delete method should remove the specified person object from the address book 0 .The search method that searches the address book for a specified...

  • IN C++ PLEASE Write a class Food that has a string attribute for name and a...

    IN C++ PLEASE Write a class Food that has a string attribute for name and a Boolean value for hasBeenEaten and a Boolean value for isSpoiled, default both Booleans to false add a method spoil() which sets isSpoiled to true Add a method eat() If hasBeenEaten is false, if isSpoiled is false, return a string that says "you eat the <insert name here>, yum!", then set hasBeenEaten to true if isSpoiled is true, return a string that says "I wouldn't...

  • Please write in Java Language Write an abstract class Shape with an attribute for the name...

    Please write in Java Language Write an abstract class Shape with an attribute for the name of the shape (you'll use this later to identify a particular shape). Include a constructor to set the name of the shape and an abstract calculateArea method that has no parameters and returns the area of the shape. Optionally, include a constructor that returns the name of the shape and its area (by calling the calculateArea method). Write a Rectangle class that inherits from...

  • please help me with this python code thank you 1. Write a Student class that stores...

    please help me with this python code thank you 1. Write a Student class that stores information for a Rutgers student. The class should include the following instance variables: (10 points) o id, an integer identifier for the student o lastName, a string for the student&#39;s last name o credits, an integer representing the number of course-credits the student has earned o courseLoad, an integer representing the current number of credits in progress Write the following methods for your Student...

  • a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...

    a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...

  • Need help asap with basic c++ question Write a class Food that has a string attribute...

    Need help asap with basic c++ question Write a class Food that has a string attribute for name and a Boolean value for hasBeenEaten and a Boolean value for isSpoiled, default both Booleans to false add a method spoil() which sets isSpoiled to true Add a method eat() If hasBeenEaten is false, if isSpoiled is false, return a string that says "you eat the <insert name here>, yum!", then set hasBeenEaten to true if isSpoiled is true, return a string...

  • Take the class Person. class Person: """Person class""" def __init__(self, lname, fname, addy=''): self._last_name = lname...

    Take the class Person. class Person: """Person class""" def __init__(self, lname, fname, addy=''): self._last_name = lname self._first_name = fname self._address = addy def display(self): return self._last_name + ", " + self._first_name + ":" + self._address Implement derived class Student In the constructor Add attribute major, default value 'Computer Science' Add attribute gpa, default value '0.0' Add attribute student_id, not optional Consider all private Override method display() Test your code with the following driver: # Driver my_student = Student(900111111, 'Song', 'River')...

  • 2- Write a program that has a Person class, a Student class, that is derived from...

    2- Write a program that has a Person class, a Student class, that is derived from Person, and a Faculty class, derived from Person as well, with the following specifications: The Person class has the following members: a. An integer private member variable named SSN. b. Two string protected member variables named firstName and lastName. C. An integer protected member variable named age. d. A constructor that takes SSN, first name, last name, and age as parameters. e. A constructor...

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