d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Troubleshooting Help
Add Reply New Topic New Poll
Member
Posts: 23,838
Joined: Feb 18 2009
Gold: 0.01
Mar 13 2013 09:52pm
Code
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;

class ResourceOne {

public:
ResourceOne();
ResourceOne(int write);
int get_status() const;
int get_writeTo() const;
void set_status(int stat);
void set_writeTo(int write);
void output(ostream &out_stream);
bool check_status(ResourceOne &res1, ResourceTwo &res2);

private:
int status;
int writeTo;

};

ResourceOne::ResourceOne() {
status = 0;
writeTo = 0;
}
ResourceOne::ResourceOne(int write) {
status = 0;
writeTo = write;
}

int ResourceOne::get_status() const {
return status;
}
int ResourceOne::get_writeTo() const {
return writeTo;
}

void ResourceOne::set_status(int stat) {
status = stat;
}
void ResourceOne::set_writeTo(int write) {
writeTo = write;
}
void ResourceOne::output(ostream &out_stream) {
out_stream << "Status is: " << status << endl;
}

class ResourceTwo {

public:
ResourceTwo();
ResourceTwo(int write);
int get_status() const;
int get_writeTo() const;
void set_status(int stat);
void set_writeTo(int write);
void output(ostream &out_stream);
friend bool check_status(ResourceOne &res1, ResourceTwo &res2);

private:
int status;
int writeTo;

};


ResourceTwo::ResourceTwo() {
status = 0;
writeTo = 0;
}
ResourceTwo::ResourceTwo(int write) {
status = 0;
writeTo = write;
}

int ResourceTwo::get_status() const {
return status;
}
int ResourceTwo::get_writeTo() const {
return writeTo;
}

void ResourceTwo::set_status(int stat) {
status = stat;
}
void ResourceTwo::set_writeTo(int write) {
writeTo = write;
}
void ResourceTwo::output(ostream &out_stream) {
out_stream << "Status is: " << status << endl;
}

bool check_status(ResourceOne &res1, ResourceTwo &res2){
bool test = 0;

test = (res1.status == 1 && res2.status ==1);

if (test == 1)
{
 cout << "Resource Available" << endl;
}
else
 cout << "Resource unavailable" << endl;

return test;
}
/*
1)
Create two classes ResourceOne and ResourceTwo. Each of these classes should have:
a) Two private variables “status” and “writeTo” representing integer value either 1/0.
b) One default constructor that initialize the “status” and “writeTo” to zero.
c) One single parameterized constructor to initialize the status of the writeTo variable.
d) Two constant accessor functions per class that return the values of status and writeTo separately
e) Two mutator functions per class that set the value of status and writeTo separately.
f) One output (member) function that outputs the resource status.
The output function should be able to print on the screen or an output file.
void output(ostream &out_stream);

g) A friend function check_status that accesses the status variables of both classes.
If status in each resource is set to “1” display “resource available” else display “resource unavailable”.
friend bool check_status(Resource1 &res1, Resource2 &res2)
{
// write status checking code here.
// return true if res1 status and res2 status is 1
// else return false.
}



*/

int main() {
ResourceOne res1;
ResourceTwo res2;

res1.set_status( 1);
res1.set_writeTo(1);
res2.set_status( 1);
res2.set_writeTo(1);
return 0;

}


i get errors on
test = (res1.status == 1 && res2.status ==1);

Resource1's
private:
int status;

and Resource 1's
bool check_status(ResourceOne &res1, ResourceTwo &res2);

need hlap pls
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Mar 13 2013 10:31pm
I notice R2 has friended bool check_status but R1 hasn't. Intended?
Member
Posts: 23,838
Joined: Feb 18 2009
Gold: 0.01
Mar 13 2013 10:33pm
Quote (Eep @ Mar 13 2013 09:31pm)
I notice R2 has friended bool check_status but R1 hasn't. Intended?


yea i figured out the problem..
just needed to add
class ResourceTwo;
at the beginning for some reason.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll