2.16: Diamond Pattern
Write a <span style="text-decoration-line: none;">program</span> that displays the following pattern:
*
***
*****
*******
*****
***
*
One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of acres in a tract of land with 389,767 square feet.
Assuming the ocean’s level is currently rising at about 1.5 millimeters per year, write a <span style="text-decoration-line: none;">program</span> that displays
1. Function Overloading : Compile time polymorphism: early binding: same function name with different types and number of arguments.
2. Virtual function: Run-time polymorphism: late binding: call function depending on where base pointer is pointing to.
Kamal would like to withdraw X Rs from an ATM. The cash machine will
only accept the transaction if X is a multiple of 100, and kamal's account balance has enough cash to
perform the withdrawal transaction. For each
successful withdrawal the bank charges 50 Rs. Calculate Kamal's account
balance after an attempted transaction.
Consider the definition of the following class:
class Sample
{
private:
int x;
double y;
public :
Sample();
//Constructor 1
Sample(int);
//Constructor 2
Sample(int, int);
//Constructor 3
Sample(int, double);
//Constructor 4
};
i. Write the
definition of the constructor 1 so that the private member variables are initialized
to 0.
ii. Write the
definition of the constructor 2 so that the private member variable x is
initialized according to the value of the parameter, and the private member
variable y is initialized to 0.
iii. Write the definition of the constructors 3 and 4 so that the private
member variables are initialized according to the values of the parameters
Consider the class declaration and main() function below. There are two errors in
the main() function. Name the errors and explain how to fix them, providing all the
code required to correct the errors.
class Game
{
public:
Game();
string getName();
int getLevel();
double getScore();
private:
string Name;
string Champion;
int Level
double Score;
};
int main()
{
Game sodoku, tetris[12];
.........(additional code)
double nScore = sodoku.Champion;
.........(additional code)
return 0;
cout << "The first tetris player is "
<< tetris.getName() << endl;
}