CSI 250L Lab 6, Spring 2012
American University of Science and Technology · Programming II Lab · 3 pages · Dr. Saeed Raheel
More CSI 250L files
- Lab 1 Solution · Spring 2012Lab · with solutionView
- Lab 1 · Spring 2012LabView
- Lab 10 Solution · Spring 2012Lab · with solutionView
- Lab 10 · Spring 2012LabView
- Lab 11 Solution · Spring 2012Lab · with solutionView
- Lab 11 · Spring 2012LabView
- Lab 12 Solution · Spring 2012Lab · with solutionView
- Lab 12 · Spring 2012LabView
Show the text of this lab
American University of Science & Technology
Department Of Computer Science
CSI 250L – Computer Programming-II Lab
Spring 2011/2012
Lab Work 6
Problem1:
Trace the following program:
a-
#include <string>
#include <iostream>
using namespace std;
class Car {
private:
int wheels;
string brand;
static int count;
public:
Car(int, string);
int getCount();
int getWheels();
string getBrand();
void setWheels(int);
void setBrand(string);
};
int Car::count = 0;
Car::Car(int c, string b) {
setWheels(c);
setBrand(b);
count++;
}
int Car::getCount() {
return count;
}
int Car::getWheels() {
return wheels;
}
string Car::getBrand() {
return brand;
}
void Car::setWheels(int w) {
wheels = w;
}
void Car::setBrand(string b) {
brand= b ;
}
int main(){
string b1 = "Honda",b2 = "Toyota";
Car c1(4, b1);
Car c2(3, b2);
cout<<"c1 values are : " << c1.getWheels() << " - " <<
c1.getBrand()<<endl;
cout<<"c2 values are : " << c2.getWheels() << " - " <<
c2.getBrand()<<endl;
cout<<"Car count when using c1: " << c1.getCount()<<endl;
c2 = c1;
c2.setBrand(c1.getBrand());
c1.setBrand("bmw");
c1.setWheels(3);
c1.setBrand(c2.getBrand());
1
cout<<"Wheels : " << c2.getWheels()<<endl;
cout<<"c1 values are : " << c1.getWheels() << " - " << c1.getBrand()
<< endl;
cout<<"c2 values are : " << c2.getWheels() << " - " << c2.getBrand()
<< endl;
cout<<"Car count when using c2: " << c2.getCount()<<endl;
system("pause");
return 0;
}
Problem 2:
Write the class definitions and implementations for the following class specification. (use
separate files for the class definition and implementation).
Supplier
Attributes
ID: a number to identify each supplier.
name: a string of characters for the supplier’s name.
Country: a string of characters for the supplier’s
location.
Methods
constructors (default values)
print.
destructor.
Set and get
Write a driver program create N objects of the class Supplier. Then the user should
choose from the following menu:
1. Display the name of a supplier knowing his ID.
2. List the information about all suppliers located in USA.
3. Exit.
Problem
3 :
2
Write the class definitions and implementations for the following class specification. The
class definition and implementation should be written in a separate file.
ComEmployee
Attributes
Name: a string to identify the name. (dynamic
allocation)
grossSales: a double to identify the gross sales
commissionRate: a double representing a percentage
count: static variable to count the instantiated objects.
.
Methods
default constructor and all arguments constructor.
set and get methods
print.
Destructor
BasePlusComEmployee
Attributes
baseSalary: a double representing the base salary
ComEmployee is the composed object
Methods
default constructor and all arguments constructor.
print: a constant function.
set and get functions.
earnings: compute the earnings as
baseSalary + (commissionRate * grossSales)
The program should do the following:
Output the total earnings of all employees.
Output the names of all employees with gross sales >10000.
3