Question

in C++: Create a class named Student that has three member variables: name - string that...

in C++:

Create a class named Student that has three member variables:

name - string that stores the name of the student
numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100.
classList - an array of strings of size 100 used to store the names of the classes that the student is enrolled in

Write the appropriate constructor(s), mutator and accessor functions for the class along with the following:

- a function that inputs all values from the user, including the list of class names
- a function that outputs the name and list of all courses
- a function that resets the number of classes to 0 and the classList to an empty list

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

#include <iostream>

#include <string>

using namespace std;

class Student {

  public:

string name;

int numClasses;

string classList[100];

Student(){}

Student(string aName, int aNumClasses) {

  name = aName;

  numClasses = aNumClasses;

}

string getName() {

  return name;

}

void setName(string aName) {

  name = aName;

}

int getNumClasses() {

  return numClasses;

}

void setNumClasses(int aNumClasses) {

  numClasses = aNumClasses;

}


void inputData(){

  

    cout<<"Enter name : ";

    cin>>name;

    cout<<"Enter number of classes: ";

    cin>>numClasses;

    cout<<"Enter "<<numClasses<<" classes : ";

    for(int i=0;i<numClasses;i++)

      cin>>classList[i];

}

void display(){

  cout<<"Name : "<<name<<endl;

  cout<<"Number of classes: "<<numClasses<<endl;

  cout<<"Classes: ";

  for(int i=0;i<numClasses;i++)

    cout<<classList[i]<<" ";

  cout<<endl;

}

void reset(){

  numClasses=0;

}

};


int main() {

Student s;

s.inputData();

s.display();

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
in C++: Create a class named Student that has three member variables: name - string that...
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
  • Implement the following class in interface and implementation files. A separate file (the main project file)...

    Implement the following class in interface and implementation files. A separate file (the main project file) shall have the main function that exercises this class. Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100 ClassList - an array of strings of size 100 used to store the...

  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • Code the following Program in C++ Define a class named Payment that contains a member variable...

    Code the following Program in C++ Define a class named Payment that contains a member variable of type float that stores the amount of the payment and appropriate accessor and mutator methods.    Also create a member function named paymentDetails that outputs an English sentence that describes the amount of the payment. Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails function to indicate that the payment is in cash. Include appropriate constructor(s)....

  • C++ Visul Studio Create a class named Vehicle. The class has the following five member variables:...

    C++ Visul Studio Create a class named Vehicle. The class has the following five member variables: • Vehicle Name • Vehicle number • Sale Tax • Unit price • Total price Include set (mutator) and get (accessor) functions for each field except the total price field. The set function prompt the user for values for each field. This class also needs a function named computePrice() to compute the total price (quantity times unit price + salesTax) and a function to...

  • 2. Create a class named Student that contains the following » idStudent. The idStudent is an...

    2. Create a class named Student that contains the following » idStudent. The idStudent is an int variable that holds the student's matric number. name. The name field references a String object holds the student's name. . major. The major field references a String object holds the student's major. . classification. The classification field references a String object holds the student's classification level (bongsu, kecil, muda, sulung) . Constructor should accept the student's matric number, name, major and classification as...

  • 7. PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName...

    7. PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData, which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailinglist The customer Number variable will be used to hold a unique integer for each customer. The mailing List variable should be a bool....

  • 7. PersonData and CustomerData classes Design a class  named PersonData with the following member variables...

    7. PersonData and CustomerData classes Design a class  named PersonData with the following member variables : lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables . Next, design a class  named CustomerData, which is derived from the PersonData class . The CustomerData class should have the following member variables : customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool....

  • Design a class named Person with fields for holding a person's name, address, and telephone number...

    Design a class named Person with fields for holding a person's name, address, and telephone number (all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes...

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

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