1. Write a program using Function Concept to Calculate Perimeter of Circle, Square, Triangle and Rectangle.
i. Function calPerimeterCircle that do not accept arguments and do not return value.
ii. Function calPerimeterSquare that do not accept arguments and return value.
iii. Function calPerimeterTriangle that accept arguments and do not return value.
iv. Function calPerimeterRectangle that accept arguments and return value
2. Please refer the following formula as guidance :
a. Perimeter of Circle = 2 π r : r = radius , use π= 22/7
b. Perimeter of Square = 4a : a = side
c. Perimeter of Triangle = a+b+c : a=side1, b=side2 and c= side3
d. Perimeter of Rectangle = 2 +(l+w) : l=length, w= width
Write a program that determines the frequency of each char in an input le. Your program
should
• read in an unknown number of chars from an input le named input.txt,
• using a function written by you, determine the frequency of occurrence of each char in
the list
• write each char followed by the frequency to the output le output.txt.
• The chars should appear in the output le in the same order as they rst appeared in
the input le.
First draw a
ow chart and then attempt the code.
Example 1
Example input and output les can be seen in Listings 9 and 10.
Listing 9: Example of input.txt
1 a
2 a
3 f
4 e
5 v
6 x
7 a
8 v
9 f
10 f
11 f
12 g
Page 4 of 5
Listing 10: Example of output.txt
1 a 3
2 f 4
3 e 1
4 v 2
5 x 1
6 g 1
Example 2
Example of additional input and output les can be seen in Listings 11 and 12.
Listing 11: Example of input.txt
1 a
2 b
3 a
4 b
5 a
6 b
7 b
Listing 12: Example of output.txt
1 a 3
2 b 4
In traditional way, there are three classes: TRUCK (number, name , NoOfWheel, Price, Capacity,
EnginePower, TypeOfConsump), BUS (number, name , NoOfWheel, Price, NoOfSeat,
EnginePower, TypeOfConsump, Color, Speed), CAR (number, name , NoOfWheel, Price,
NoOfSeat, EnginePower, TypeOfConsump, Color, Speed).
Divide the above three classes into two base classes and three derived classes. Each class will
contain two member functions, getdata() to get that class data from user and putdata() to display that
class data on the screen. How the above member data of three classes will be distributed into five
classes as shown in the following diagram.
Use the aggregation (composition)
concept to define and implement the
class line(pl.x, pl.y, p2.x, p2.y) by using
two points variables P 1, and P2 of type
point2D class defined in QI. Beside the
two points Pl and P2, the line class has
the following functions: print(),
MoveRel(Dx,Dy) (use the point2D's
MoveRel(Dx,Dy) function of the two
points to achieve that), line(),
Use the point2D class as base class
to derive a new class called
Point3D(x,y,z). In addition to the
derived variables and functions
(methods) the new class has the
variable z with the functions setZ(z1),
getZ(), MoveRel(Dx,Dy,Dz), print(), and
the constructers point3D(),
point3D(x1,y1,z1,pColor), the destructor
-point3D(). Determine which function
is an override function and which one
is an overloaded function of the base
class.
Define the class point2D(x,y) for
the x, y coordinates. The class has x, y
and color as member variables and as
member function has setXY(x1,y1),
setColor(pColor), MoveRel(Dx,Dy),
getX(), getY(), getColor(pColor), Print(),
the constructers point2D(),
point2D(x1,y1,pColor), the destructor
-point2D(). The MoveRel(Dx, Dy)
function changed the x, y coordinates
by the amount of Dx, and Dy,
respectively (ex: x=x+Dx, y=Y+Dy).
Determine which function is accessor
and which one is mutator.
Write a program to read numbers from a file.
C++ programming
Create a structure called Exam that includes exam ID (string), name of the subject (string),
registration fee (double) and the number of students registered during a week (7 days) (int
array). • Write a function called getExamDetails() which is the data type of Exam that reads the
details of the Exam and store them in the variable of the Exam structure.
Hint: Use the given function prototype as
Exam getExamDetails (Exam e);
• Write a function called calExamFee() which takes three parameters, registration fee for
the exam, the number of students registered during a week (7 days) array and the size of the array. Find the total exam registration fee during the week and print the total exam
registration to the screen. • Call the getExamDetails() and calExamFee() in the main function to print the following
output as required.
In traditional way, there are three classes: TRUCK (number, name , NoOfWheel, Price, Capacity, EnginePower, TypeOfConsump), BUS (number, name , NoOfWheel, Price, NoOfSeat, EnginePower, TypeOfConsump, Color, Speed), CAR (number, name , NoOfWheel, Price, NoOfSeat, EnginePower, TypeOfConsump, Color, Speed).
Divide the above three classes into two base classes and three derived classes. Each class will contain two member functions, getdata() to get that class data from user and putdata() to display that class data on the screen. How the above member data of three classes will be distributed into five classes as shown in the following diagram.