Question

C++Exercise 1: Create a class Resource. The class should have: a) Two private variables status and writeTo representing integerC++

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

#include <iostream>
using namespace std;

class Resource
{
private:
int status,writeTo;

public:
Resource()
{
status = 0;
writeTo = 0;
}
Resource(int writeTo)
{
this->writeTo = writeTo;
}
int getStatus()const
{
return status;
}
int getWriteTo()const
{
return writeTo;
}

void setStatus(int status)
{
this->status = status;
}
void setWriteTo(int writeTo)
{
this->writeTo = writeTo;
}
void output(ostream &out_stream)
{
out_stream<<"Status : "<<status<<" Write To : "<<writeTo;
}

friend bool check_status(Resource &res1, Resource &res2);
};

bool check_status(Resource &res1, Resource &res2)
{
// Define status checking code here.
// return true if res1 status and res2 status are both 1
if(res1.status == 1 && res2.status == 1)
return true;
// else return false.
else return false;
}

int main() {
Resource r1(0);
Resource r2(1);

r1.output(cout); // cout is used to display on screen

if(check_status(r1,r2))
cout<<"\nStatus of resource r1 and r2 are same ";
else
cout<<"\nStatus of resource r1 and r2 are not same ";
return 0;
}

output:

Status : 0 Write To : 0
Status of resource r1 and r2 are not same

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
Exercise 1: Create a class Resource. The class should have: a) Two private variables status and w...
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
  • Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and...

    Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question. Exercise #4: Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. Exercise #5: There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer. The constructor method has...

  • Using separate files, write the definition for a class called Point and a class called Circle. Th...

    Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...

  • Programming: Create a class called City with two public variables: a string to store the name...

    Programming: Create a class called City with two public variables: a string to store the name of the city and a float to store the average temperature in Fahrenheit. Create one object of the class that you create and ask the user to enter the city name and the average temperature in Fahrenheit. Store these in the object of the class that you create. Then display the contents of the class. Once that is working, make the variables private and...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • U8ing separate files, write th definition for a clas called Poit and a class called Cirele...

    U8ing separate files, write th definition for a clas called Poit and a class called Cirele 1. The class point has the data members (double) and y (double) for the x and y coordinates The class has the following ember functions a) void set x (double) to set the x data member b) void set y(double) to set the y data member c) double get-x() to return th the data member d) double get yO to zeturn the the y...

  • 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...

  • 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...

  • Please help me to write a c++ program that will Implement a HotelRoom class, with private...

    Please help me to write a c++ program that will Implement a HotelRoom class, with private data members: the room number, room capacity (representing the maximum number of people the room can accommodate), the occupancy status (0 or the number of occupants in the room), the daily room rate. Member functions include: • a 4-argument constructor that initializes the four data members of the object being created (room number, room capacity, room rate, occupancy status) to the constructor's arguments. The...

  • 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...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

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