السلآم عليكم ورحمة الله وبركآته
هذآ البرنآمج مع الآوت بوت تبعه ،
أبي حدآ يسآعدنيَّ ويشرح لي البرنآمج كآمل مع Trace <~ تتبع
وأكون شآكره لُكم
//The header files
#include<iostream>
#include<iomanip>
using namespace std;
//---------------------------
class Shipment{
int number;
string location;
string destination;
double weight;
double cost;
public:
Shipment();
void setNumber(int);
void setLocation(string);
void setDestination(string);
void setWeight(double);
void setCost(double);
int getNumber();
string getLocation();
string getDestination();
double getWeight();
double getCost();
};
//------------------------------
//default constructor
Shipment::Shipment(){
number =0;
location = "";
destination ="";
weight=0;
cost=0;
}
//------------------------------
//Set member function
void Shipment::setNumber(int n)
{
number = n;
}
void Shipment::setLocation(string l)
{
location = l;
}
void Shipment::setDestination( string d)
{
destination = d;
}
void Shipment::setWeight( double w)
{
weight=w;
}
void Shipment::setCost(double c)
{
cost = c;
}
//-----------------------------
//get member function
double Shipment::getCost() {
return cost;
}
int Shipment::getNumber()
{
return number;
}
double Shipment::getWeight()
{
return weight;
}
string Shipment::getLocation()
{
return location;
}
string Shipment::getDestination()
{
return destination;
}
//----------------------------
double calculateCost(double w)
{
double result = w * 20;
return result;
}
//---------------------------
void printShipmentDetail(Shipment s)
{
cout<< "Displaying Shipment Information\n";
cout<<setw(30)<<setfill('-');
cout<<"\n Number "<<s.getNumber()
<<"\n Location "<< s.getLocation()
<<"\n Destination "<< s.getDestination()
<<"\n Weight "<< s.getWeight()
<<"\n Cost "<< s.getCost();
}
//---------------------------
int main()
{
Shipment package;
double cost;
printShipmentDetail(package);
cout<<"Setting shipment information \n";
package.setDestination("Jeddah");
package.setLocation("Riyadh");
package.setNumber(87479);
package.setWeight(40);
cout<<"Calculating Shipment Cost \n";
cost = calculateCost(package.getWeight());
package.setCost(cost);
printShipmentDetail(package);
return 0;
}
//end of the program
//------------------------------الآوت بوت
Displaying Shipment Information
---------------------
Number 0
Location
Destination
Weight 0
Cost 0Setting shipment information
Calculating Shipment Cost
Displaying Shipment Information
---------------------
Number 87479
Location Riyadh
Destination Jeddah
Weight 40
Cost 800
