FMT Engineer
FMT Engineer
c.print();
return 0;
}
Faculty of Engineering & Architecture
c. class Box {
public: OUTPUT
static int objectCount;
Box(double l = 2.0, double b = 2.0,
double h = 2.0) {
cout <<"Constructor called." << endl;
length = l;
breadth = b;
height = h;
objectCount++; }
double Volume() {
return length * breadth * height; }
private: FUNCTION
double length;
double breadth;
double height; };
int Box::objectCount = 0;
int main(void) {
Box Box1(3.3, 1.2, 1.5);
Box Box2(8.5, 6.0, 2.0);
cout << "Total objects: " << Box::objectCount << endl;
return 0; }
d.
int main() {
class Animal { Animal myAnimal;
public: Pig myPig;
void animalSound() { Dog myDog;
cout << "The animal makes a sound \n" ; myAnimal.animalSound();
} }; myPig.animalSound();
class Pig : public Animal { myDog.animalSound();
public: return 0;
void animalSound() {
cout << "The pig says: wee wee \n" ; OUTPUT
} };
class Dog : public Animal {
public:
void animalSound() {
cout << "The dog says: bow wow \n" ;
} };
Faculty of Engineering & Architecture
3. Coding Questions.
a. Const Co. is a construction company that one of the services is surrounding the gardens
with bricks. The boss Mr. Brickstone ask to the programming department of the company
to write a program in C++ to calculate the cost of any garden by checking the garden
shape(area of triangle or rectangle) and material type (fence). Fence cost is 200TL/m.
Programming Steps:
You have to use multiple inheritance to solve this problem. There should be two base
classes as shape and material and two derived classes from these base classes as triangle
and rectangle.
You should use a constructor to initialize the brick cost price.
Also you have to put a static variable to count and print how many times this program is
executed at the end.
Using formulas, setter and getter functions and inheritance methods should be similar to
the multiple inheritance example.
#include <iostream>
// Derived class
class Rectangle: public Shape, public PaintCost {
public:
int getArea() {
return (width * height);
}
};
int main(void) {
Rectangle Rect;
int area;
Rect.setWidth(5);
Rect.setHeight(7);
area = Rect.getArea();
Faculty of Engineering & Architecture
return 0;
}
c. Write a program and use function overloading to give the following output:
Output:
Operation type (Addition or Multiplication): +
Number of operands (2 or 3): 2
Enter no1: 5
Enter not2:6
Result=30
d. Assume that you are working in a company as a programmer that laying parquet to
houses. Manager asked you to write a program to calculate the cost of laying parquet in
a house. The program should take the area of the house room by room.
Eg. Room1: 25m2
Room2: 30m2
+ Room3: 40m2
________________________
Total=95 m2
After calculating the total area, the program should multiply it to the unit(m2) price of the
parquet.
Eg. Total=95 m2
Parquet(m2)=200TL/ m2
Faculty of Engineering & Architecture
Cost= 95x200=19000TL