Write c++ program to find efficiency of petrol engine, diesel engine and steam engine.
Suppose you are playing a killing game and have to kill few of your enemies. You are at a cliff
and from there you can see few of them. You see the enemies at your height only. Therefore,
you can only kill at the same height. The enemies are forming a balanced binary tree where
their General is at the top of the other cliff, his two commanders are on the first level below
him. The soldiers are at the lowest level. Total four soldiers are appointed. Under both the
commanders exact two soldiers serve.
You have to make a strategy to kill the left commander first, than whoever takes his position
kill him. Now start killing the right side with same strategy until only one enemy is left at left
side. Now increase your height and kill the General. You can only win if only three of your
enemies are left.
Display the enemies who are left and who have been killed. Don’t forget to print your victory
message.
Create a class GradeBook that maintains the course name as a data member so that it can be used
or modified at any time during a program's execution. The class contains member functions
setCourseName, getCourseName and displayMessage. Member function setCourseName stores a
course name in a GradeBook data member, member function getCourseName obtains a
GradeBook's course name from that data member. Member function displayMessage which now
specifies no parameters but displays a welcome message that includes the course name.
The class should also take input for student name (string) and student marks (float). The
number of students for which grades are to be entered should be specified by the user. The
program should also calculate and print the grades for students.
Implement a class called Fractions having two private integer data members used for a
fraction’s numerator and denominator.
The Fraction Class’s default constructor should provide both data members with default values
of 1 if no explicit user initialization is provided. It must also prohibit 0 as the denominator
value.
Further, provide member functions for displaying an object’s data values i.e given an object,
its numerator and denominator. Also provide the class with member functions that are capable of
adding, subtracting, multiplying and dividing two Fraction objects according to the following
formulas:
Sum of two fractions: a/b + c/d = (ad + cb) / bd
Difference of two fractions: a/b – c/d = (ad – cb) / bd
Product of two fractions a/b * c/d = ac/ bd
Division of two fractions: a/b / c/d = ad /bc
Implement a class named Rectangle that contains following private members:
Two double data fields that specify the width and height of the rectangle. A string data field, named color, that specifies the color of a rectangle.
You should provide a no-argument constructor that creates a default rectangle having width and
height of 2 units and color set to black. You should also provide an overloaded constructor that
creates a rectangle with the specified width and height. In addition you should provide methods
to only set the color of the rectangle. Further, you should provide a member function named
getArea() that returns the area of this rectangle and a function named getPerimeter() that returns
the perimeter.
Write a test program that creates two Rectangle objects. Assign width 10 and height 20 to the
first object and width 34.5 and height 15.9 to the second object. Assign color red to all
Rectangle objects and find their areas and perimeters.
Implement a class Address. An address has
a house number,
a street,
a city,
a state and
a postal code.
Supply two constructors:
the default no-argument constructor that initializes different members
one with complete address.
Supply a print function that prints the address with the street on one line and the city,
state, and postal code on the next line.
Supply a method verifyAddress that tests whether an address is valid (and does not
contain default values)
Supply a method compareTo that tests whether one address comes before another when
the addresses are compared by postal code
Write a small program to test your class.
Implement a class Student. A Student has a first name (string), last name (string) and CGPA (float).
Write a default constructor, an overloaded constructor with three parameters (first name, last
name and CGPA). In addition provide methods (functions) to return the full name and CGPA.
Write a small program to test your class by creating an object and invoking different functions
to get and set different class members.
WAP in C to calculate area and perimeter of rectangle, area and
circumference of circle using switch case statement.
Design an algorithm which gets a natural value, n, as its input and calculates odd numbers
equal or less than n. Then write them in the standard output.
Write the definition of the function, nodeCount, that returns the number of nodes in a binary tree. Add this function to the class binaryTreeType and create a program to test this function