Question

1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files)...

1a. Create a class named Computer
- Separate declaration from implementation (i.e. Header and CPP files)
1b. Add the following private member variables
- an int variable named year
- a string variable named model
- a string variable named purpose
1c Add the following public functions:
- Default constructor which sets numeric members to -1 and string members to the empty string
- Destructor to print "Removing instance from memory"
- A non-default constructor to set the year and model variables only. The "purpose" variable should be set to the empty string.
- A non-default constructor to set all THREE member variables.
- Accessor and Mutators for all THREE member variables

please have a run for c++, visual studio. thank you

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

CODE IN C++

#include <iostream>
#include<string>

using namespace std;


class Computer
{
private:
int year;
string model,purpose;
public:
  
Computer(); //default constructor
~Computer(); //destructor
  
  
Computer(int y,string const& m,string const& p); //nondefault constructor

//accessors and mutators
void setYear(int y1);
int getYear( void );
  
void setModel(string const& m);
string getModel( void );
  
void setPurpose(string const& p);
string getPurpose( void );
  
};

Computer::Computer(void)
{
year=-1;
model="";
purpose="";


}
Computer::Computer(int y,string const& m,string const& p)
{
year=y;
model=m;
purpose=p;


}
Computer::~Computer(void)
{
cout << "Removing instance from memory" << endl;
}

void Computer::setYear( int y1 )
{
year= y1;
}
int Computer::getYear( void )
{
return year;
}
void Computer::setModel( string const& m )
{
model=m;
}
string Computer::getModel( void )
{
return model;
}
void Computer::setPurpose( string const& p )
{
purpose=p;
}
string Computer::getPurpose( void )
{
return purpose;
}


int main()
{
Computer com;


Computer com1(1998,"unique","building");





  
com.setYear(1998);
cout << "Year is : " << com.getYear() <<endl;

com.setModel("unique");
cout << "Model is : " << com.getModel() <<endl;

com.setPurpose("building");
cout << "purpose is : " << com.getPurpose() <<endl;

return 0;
}



OUTPUT

Add a comment
Know the answer?
Add Answer to:
1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files)...
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
  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

  • The class declaration (interface) and the function definitions (implementation) must be in separate files - the...

    The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. Write a class called BankAccount that has: a string data member called customerName, a string data member called customerID, and a double data member called customerBalance a constructor that takes two strings and a double (name, ID, balance) and uses them...

  • Write a class declaration named Circle with a private member variable named radius.

     in C++ Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159*radius*radius. Add a default constructor to the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign its value to the radius...

  • Write a class declaration named Circle with a private member variable named radius.

    CODE IN C++Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159 * radius * radius. Add a default constructor the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign radius...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

  • A. (C++) Write a class declaration named Circle, with a private member variable, radius. Write set...

    A. (C++) Write a class declaration named Circle, with a private member variable, radius. Write set and get functions to access the radius variable, and a function named get getArea which returns the area of the circle. The area is calculated as 3.14 * radius * radius. B. Write a constructor to the circle that accepts an argument and assign its value to the radius member variable. C. Add a static member variable that accounts for the currently active circle...

  • Implement the Message class using a header and implementation file named Message.h and Message.cpp respectively. In...

    Implement the Message class using a header and implementation file named Message.h and Message.cpp respectively. In addition to the two Message class files, you must write a driver. The driver must create a Message array that is capable of holding 100 messages (make sure that you don’t exceed the maximum number of Messages). It then must read all Messages from a file named messages.txt (ordered date\n sender\n recipient\n body\n), sort the Messages based on date, find a Message based on...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

  • Create the header file named “Complex.h” that contains the following class: The class Complex represents a...

    Create the header file named “Complex.h” that contains the following class: The class Complex represents a complex number which is a number of the form a + bi where a and b are real numbers and i2 = −1. The class should contain: Private double field named real. Private double field named imaginary. Public default constructor that assigns 1 to real and 0 to imaginary. Public overloaded constructor that takes a double as a parameter named real. It assigns real...

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