Question

Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.  

and please put comment with code!

Problem:2 1. Class Student Create a Hello C++! I love CS52 Program 10 points Create a program that simply outputs the textIn the main function, right below where you output Hello C++! I love CS52, create an object from the class. You can name th5. Instance Variable, Also Know as Data Members Add a keyword private with a colon. Add a member variable to the Student clas7. Get and Set Methods (getter and setter or it can also be called mutators and accessors) Add getName and setName methods toThe output should look similar like below, assuming that your parameter for the setName is Angelina Jolie ello C++! I love

Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as which contain the main function, define a new class called "Student". The word student must start with an uppercase. It can be an empty class, without property and functionality.
In the main function, right below where you output "Hello C++! I love CS52", create an object from the class. You can name the object however you like with a meaningful word. 3. Basic Constructors Add a keyword public with a colon before implements a constructor. Modify your "Student" Class to add a constructor. Make the constructor output the text "Default Constructor is called!" This constructor will not have an argument. 4. Multiple Constructors Modify the Student class so that it has another constructor. Adding a new constructor where it accepts a parameter called name of type String. Make this second constructor print the name parameter using cout object. Simply, taking the argument and use cout to output the name to the terminal screen. Finally, change your main function so that when you create the Student object, you pass in a name. Pass in your name to the constructor when you call a new constructor
5. Instance Variable, Also Know as Data Members Add a keyword private with a colon. Add a member variable to the Student class. A variable with type string with a name "name". In your second constructor, set the value of the "name" instance variable using the name" parameter that you pass in. -Assigning the parameter by using this-> keyword. Remove the cout line form the class 6. Methods Define a method (function) in the class. Add a method to your Student class called "printName". Make this method output the text "My name is " followed by the value of the name instance variable. Run and call this method in the main function. The output should be similar like the following, assuming your name is "Angelina" Hello C++! I love CS52 Default Constructor is called! y name is Angelina Press any key to continue.. .
7. Get and Set Methods (getter and setter or it can also be called mutators and accessors) Add getName and setName methods to your class. The getName method will return the variable name. The setName will pass the parameter value to the variable name -Call those two methods in the main function. For the setName method, please pass your name and last name into the methods. Do all this just before calling printName0
The output should look similar like below, assuming that your parameter for the setName is "Angelina Jolie" ello C++! I love CS52 Default Constructor is called! y name is Angelina Jolie Press any key to continue .. 8. Composition Above where you defined the Student class, define a class called "Brain" Give the Brain class a constructor Make the Brain class print the textI think I am smart!". Make the Brain class print the text "I think I am smart!". Give the Student class a private instance variable of type "Brain", and called "myBrain". Run your program and it should look similar like below Hello C++! I love CS52 think I am smart Default Constructor is called! I think I am smart y name is Angelina Jolie Press any key to continue Success, yeah!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution::-

#include <iostream>

using namespace std;
class Brain
{//Define class Brain
public:
Brain()
{//Default constructor of Brain class.
cout <<"\nI think I am smart";
}
};

class Student
{//Define Student class.
private:
//Private member of Student class "name".
string name;
public:
//All public member of Student class define here.
Student()
{
//Default constructor of Student class.
cout<<"\nDefault constructor called";
}
string setName(string name)
{//setName function,Using this operator we have set the name.
this->name = name;
}
string getName(string name)
{//getName function return name.
return name;
}
void printName()
{//printName function print the name.
cout<<"\nMy name is "<< name;
}
};

int main()
{//Define Main function.
string name;
cout<<"Hello C++ I Love CS52";
Student obj; //Creating object of Student class.
name = obj.getName("Angeline Jolie");//Passing name to the getName function.
obj.setName(name);//calling setName function.
Brain mybrain;//Creating object of Brain class.
obj.printName();//calling printName function.
return 0;
}

Hello C++ I Love CS52                                                                                              

Default constructor called                                                                                         

I think I am smart                                                                                                 

My name is Angeline Jolie

Add a comment
Know the answer?
Add Answer to:
Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...
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
  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solu...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solutions. Instructions 1. Read instructions carefully! 2. Use C++ syntax only, C syntax will not be accepted. 3. Always use braces to define blocks. 4. Indent all lines within a block. Each block requires one more tab. 5. Organize your code well with proper formatting and a single...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solutions. 1. write the code using function 2. Please try to implement a function after the main function and provide prototype before main function. Total Characters in String Array 10 points Problem 2 Declare a string array of size 5. Prompt the user enter five strings that are...

  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • Last picture is the tester program! In this Assignment, you will create a Student class and...

    Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...

  • // Client application class and service class Create a NetBeans project named StudentClient following the instructions...

    // Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...

  • please help Write a simple program with Student class having STL list of Record's structure as...

    please help Write a simple program with Student class having STL list of Record's structure as a member. 1. Records of the Students are not accessible to the outside world. 2. Student shall output its standing (Freshman, Sophomore etc). 3. A Student can only be created with the name 4. A class can only be added if there is a class name and the passing grade. Driver program creates a Student, adds few classes to the Student's records, then prints...

  • Please do this in C++. Thank you in advance. Note that you have to carefully create...

    Please do this in C++. Thank you in advance. Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions. Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names. Create public getters and setters...

  • 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