Sei sulla pagina 1di 4

#include <iostream>

using namespace std;

double & GetWeeklyHours()


{
double h = 46.50;
double &hours = h;

return hours;
}
//---------------------------------------------------------------------------
double * GetSalary()
{
double salary = 26.48;
double *HourlySalary = &salary;

return HourlySalary;
}
//---------------------------------------------------------------------------
int main()
{
double hours = GetWeeklyHours();
double salary = *GetSalary();

cout << "Weekly Hours: " << hours << endl;


cout << "Hourly Salary: " << salary << endl;

double WeeklySalary = hours * salary;

cout << "Weekly Salary: " << WeeklySalary << endl;

return 0;
}

-----------------------------------------------------------------------------------
---------------------------------------
#include <iostream>
#include <string>

using namespace std;

class Breads
{
private:
int code;
double price;
string name;

public:
Breads(); //default constructor
Breads(int, double, string); //overload constructor
~Breads(); //destructor

void setCode (int); //mutator


void setPrice (double); //mutator
void setBreadname (string); //mutator

int getCode();
double getPrice();
string getBreadname();
};

Breads::Breads()
{
code = 0;
price = 0.0;
name = "";
}

Breads::Breads(int jcode, double jprice, string jname)


{
code = jcode;
price = jprice;
name = jname;
}

Breads::~Breads()
{
}

void Breads::setCode (int jcode)


{
code = jcode;
}

void Breads::setPrice (double jprice)


{
price = jprice;
}

void Breads::setBreadname (string jname)


{
name = jname;
}

int Breads::getCode()
{
return code;
}

double Breads:: getPrice()


{
return price;
}

string Breads::getBreadname()
{
return name;
}

int main()
{
int number;
double price;
int code;
Breads object [100]; //declare array

cout << "How many bread types to enter? "; //prompt the user to enter
cin >> number;

for (int n = 1; n <= number; n++)


{
cout << endl << endl<< "Enter the information of bread #" << n << endl;
cout << "Bread Code : " ;
cin >> code;

switch (code)
{
case 101 :
object[n].setBreadname("Plain croissant");
break;

case 102 :
object[n].setBreadname("Cream-filled Croissant");
break;

case 103 :
object[n].setBreadname("Sausage Croissant");
break;

case 202 :
object[n].setBreadname("Plain Bun");
break;

case 204 :
object[n].setBreadname("Sambal Bun");
break;

case 205 :
object[n].setBreadname("Cheese Bun");
break;

case 301 :
object[n].setBreadname("Plain Braid");
break;

case 305 :
object[n].setBreadname("Cheese Braid");
break;

case 306 :
object[n].setBreadname("Sugar Braid");
break;

}
cout << "Bread Name : " << object[n].getBreadname() << endl;
cout << "Price (RM) : " ;
cin >> price;
object[n].setPrice(price);
}

cout << endl << endl << endl << "No\t\tBread Code\t\tBread Name\t\tPrice
(RM)" << endl;

for (int n = 1; n <= number; n++)


{
cout << endl << n << "\t\t" << code << "\t\t\t" << object[n].getBreadname()
<< "\t\t" << object[n].getPrice() << endl;
}

//cout << endl << "Average Price(RM) : " << / number << endl << endl; (PENDING
KAT SINI)

system ("pause");
return 0;
}

Potrebbero piacerti anche