Cse1201 Lab Assignment 1
Cse1201 Lab Assignment 1
Some operators checks about the relationship between two values and these operators are
called relational operators. Given two numerical values, your job is to find the relationship
between them. That is (i) First one is greater than the second (ii) First one is less than the
second or (iii) First and second one is equal.
Input
First line of the input is an integer t (t < 15) which denotes how many sets of inputs are there.
Each of the next t lines contain two integers a and b (|a|,|b| < 1000000001).
Output
For each line of input produce one line of output. This line contains any one of the relational
operators ‘>’, ‘<’ or ‘=’, which indicates the relation that is appropriate for the given two
numbers.
Sample Input
10 20
20 10
10 10
Sample Output
<
>
2. Design a class named Student that has two private data – student id and GPA. The class
should contain a parameterized constructor to initialize its data member, and one method to
display the information. Now write a C++ program that will use an array of Student objects to
represent information about 3 students. Your program should take input from the keyboard
and display the information of the 3 students.
3. Write a C++ program that will have three functions namely max which has three double type
parameters, max that has three integer type parameters, and max that has two integer
parameter. All of the mentioned function will return the maximum value among the values
received through parameter.
4. Suppose, you have two classes called scientist and manager. Both classes have two private
data that takes the same name income. Now your job is to keep a function called
compare_income() which is the friend of the both classes. This function will compare the
income of scientist and manager, and print a message announcing who have higher income.
5. You have to create a complex class with the following data and functions.
data:
1. double real
2. double imaginary
Methods:
1. complex ( ) – initializes the real and imaginary values to 0.
2. complex (double val )- initialize the real and imaginary values to val.
3. complex ( double r, double i) - initialize the real to r and imaginary to i.
4. complex add(complex c)- add the complex object with another complex
object c and return a new complex object.
5. complex sub (complex c) - subtract complex object c from the complex object
and return a new complex object.
6. void display( )- display the complex number in (real, imaginary i) format.
Output:
int main()
{
complex c1(2,3);
complex c2(4,-5);
complex c3=c1.add(c2);
c3.display(); // (6,-2i)
c3=c1.sub(c2);
c3.display(); // (-2,8i)
return 0;
}
6. Create a class SavingsAccount. Use a static variable annualInterestRate to store the annual
interest rate for all account holders. Each object of the class contains a private instance
variable savingsBalance indicating the amount the saver currently has on deposit.
Provide method calculateInterest() to calculate the monthly interest by multiplying the
savingsBalance by annualInterestRate—this interest should be added to savingsBalance.
Provide a static method modifyInterestRate(double r) that sets the annualInterestRate
to a new value.
Provide a parameterized constructor to initialize the savingsBalance.
In main method, create two savingsAccount objects, saver1 and saver2, with balances of
$2000.00 and $3000.00, respectively.
Set annualInterestRate to 4%, then calculate the interest and print the new balances for both
objects. Next, set the annualInterestRate to 5%, calculate interest and print the new balances
for both savers.
7. The account class contains a private variable which is balance of an account, and a pure
virtual method to calculate the yearly interest. It also has two functions for deposit and
withdraw money.
Create two derived class for saving and current account. For savings account, the interest rate
is 10% and for current account the interest rate is 6%. Redefine the interest function in these
classes. Use parameterized constructor to initialize the balance.
From the main method, use base class reference to implement polymorphism.