I am having trouble with the bool function in this code.
I am having trouble with the bool function in this code. Can anyone help me figure out how to write it. I need a
yes or no answer and then I need to either return the regular price or a discounted price. So if the answer is yes, then I need to return the original price * .25 and if no I need to return the original price.
My code is below:
.h file:
class Computer
{
private:
string edition;
string brand;
int sizeHardDrive;
double price;
bool refurbishedComputer;
public:
Computer(string edt, string brd, int size, double prc, bool refurb);
Computer();
string getEdition();
string getBrand();
int getSizeHardDrive();
double getPrice();
void setEdition(string edt);
void setBrand(string brd);
void setSizeHardDrive(int size);
void setPrice(double prc);
bool refurbishedComputer;
double calcDiscount();
void printInfo();
~Computer();
};
function.ccp file
#include “Computer.h”
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
Computer::Computer()
{
edition = “unknown”;
brand = “unknown”;
sizeHardDrive = 0;
price = 0;
refurbishedComputer = true;
}
Computer::Computer(string edt, string brd, int size, double prc, bool refurb)
{
this->edition = edt;
this->brand = brd;
this->sizeHardDrive = size;
this->price = prc;
this->refurbishedComputer = refurb;
}
Computer::~Computer() {
}
string Computer::getEdition()
{
return edition;
}
string Computer::getBrand()
{
return brand;
}
int Computer::getSizeHardDrive()
{
return sizeHardDrive;
}
double Computer::getPrice()
{
return price;
}
void Computer::setEdition(string edt)
{
this->edition = edt;
}
void Computer::setBrand(string brd)
{
this->brand = brd;
}
void Computer::setSizeHardDrive(int size)
{
this->sizeHardDrive = size;
}
void Computer::setPrice(double prc)
{
this->price = prc;
}
void refurbishedComputer(bool refurb)
{
return refurb;
}
double Computer::calcDiscount()
{
return{ (prc * .25) – prc };
}
void printInfo()
{
cout << “Computer Edition: ” << endl;
cout << “Computer Brand: ” << endl;
cout << “Size of Hard Drive: ” << endl;
cout << “Computer Price ” << endl;
cout << “Refurbished? (y/n) ” << refurbishedComputer << endl;
cout << fixed << setprecision(2);
}
Main.ccp file
#include “Computer.h”
#include <string>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
// declare object with default constructor
{
Computer chromebook1;
chromebook1.setEdition(“First”);
chromebook1.setBrand(“Google”);
chromebook1.setSizeHardDrive(562);
chromebook1.setPrice(399.99);
chromebook1.setrefurbishedComputer(bool refurb)
cout << “Edition: ” << chromebook1.getEdition() << endl;
cout << “Brand: ” << chromebook1.getBrand() << endl;
cout << “Size of Hard Drive” << chromebook1.getSizeHardDrive() << endl;
cout << “Price: ” << chromebook1.getPrice() << endl;
cout << “Discounted Price: ” << chromebook1.refurbishedComputer << endl;