Weekly Assignment-6-OOP-C++
Weekly Assignment-6-OOP-C++
1. Add comments to every class following the same style you have done in week-4 and
week-5 assignments.
2. Your answer should also include output of every program in your system.
3. Also draw the UML – class diagram of each program.
Figure - 2
SOLUTION:
#include<iostream>
#include<string>
using namespace std;
// Pizza class declaration
class Pizza
{
//Private variables
private:
string topping;
int diameter;
double price;
// Constant member fields
const static string STDTOP;
const static int STDSIZE;
const static double STDPRICE;
public:
// Constructor
Pizza(const string = STDTOP, const int = STDSIZE,const double = STDPRICE);
void setValues();
// Function prototype
void displayValues();
};
// Constructor
// assigning the values in the approprite class field
Pizza::Pizza(const string top, const int size,const double price)
{
topping = top;
diameter = size;
// Calling the member function
this->price = price;
}
// display function
void Pizza::displayValues()
{
cout << "a " << diameter << " inch " << topping <<
" pizza. Price $" << price << endl;
}
// setvalues function
void Pizza::setValues()
{
const double TOPPINGPREMIUM = 1.00;
const double SIZEPREMIUM = 1.50;
cout << "Enter topping ";
cin >> topping;
//************************************************
// Function main
//************************************************
int main()
{
// creating instance object of the class pizza
Pizza aPizza;
char standard;
cout << "The standard pizza is: ";
aPizza.displayValues();
cout << "Let me take your order" << endl;
cout << "Do you want the standard pizza - y or n? ";// Asks the user to respond yes or no
if(standard != 'y')
aPizza.setValues();//assigning new values to pizza's data file
cout << "Your order is ";
aPizza.displayValues();// displays the user's complete order
return 0;
}
OUTPUT 1:
OUTPUT 2:
#include<iostream>
#include<string>
using namespace std;
class Pizza
{
private:
string topping;
int diameter;
double price;
const static string STDTOP;
const static int STDSIZE;
const static double STDPRICE;
public:
Pizza(const string = STDTOP, const int = STDSIZE,const double = STDPRICE);
void setValues();
void displayValues();
};
void Pizza::displayValues()
{
cout << "a " << diameter << " inch " << topping <<
" pizza. Price $" << price << endl;
}
void Pizza::setValues()
{
const double TOPPINGPREMIUM = 1.00;
const double SIZEPREMIUM = 1.50;
cout << "Enter topping ";
cin >> topping;
if(topping != STDTOP)
price = STDPRICE + TOPPINGPREMIUM;
cout << "Enter size ";
cin >> diameter;
int main()
{
Pizza stdPizza;
Pizza special("pineapple");
Pizza deluxeSpecial("sausage", 16);
Pizza veryDeluxeSpecial("lobster", 20, 17.99);
return 0;
}
OUTPUT:
UML CLASS- DIAGRAM:
SOLUTION:
#include<iostream>
#include<string>
using namespace std;
public:
// Constructor
Name(string, string, string);
// Function prototype for display function
void displayFullName();
};
// display function
void Name::displayFullName()
{
cout << first << " " << middle <<
" " << last << endl;
}
public:
// Constructor
CreditData(double, double = 0);
// Function prototype for display function
void displayCreditData();
};
// displayCreditData()function
void CreditData::displayCreditData()
{
double creditLeft = maxBalance - currentBalance;
cout << "Current balance: $" << currentBalance <<"\nMaximum balance $" <<
maxBalance <<"\nCredit left: $" << creditLeft << endl;
}
// constructor
Customer(string, string, string,double, double, string);
// Function prototype for display function
void showCustomer();
};
// display function
void Customer::showCustomer()
{
cout << "Customer data:" << endl;
name.displayFullName();
cout << phoneNumber << endl;
credit.displayCreditData();
}
//************************************************
// Function main
//************************************************
int main()
{
// Creating a customer object
int x;
const int TIMES = 2;
string first, middle, last, phone;
double bal, lim;