CPP
CPP
Tutorial 2(18.09.2020)
1. Assuming there are 7.481 gallons in a cubic foot, write a program that asks the user to enter a
number of gallons, and then displays the equivalent in cubic feet.
2. Write a program that generates the following table:
1990 135
1991 7290
1992 11300
1993 16200
Use a single cout statement for all output.
3. A library function, islower(), takes a single character (a letter) as an argument and returns a
nonzero integer if the letter is lowercase, or zero if it is uppercase. This function requires the
header file CTYPE.H. Write a program that allows the user to enter a letter, and then displays
either zero or nonzero, depending on whether a lowercase or uppercase letter was entered.
(See the SQRT program for clues.)
4. On a certain day the British pound was equivalent to $1.487 U.S., the French franc was
$0.172, the German deutschemark was $0.584, and the Japanese yen was $0.00955. Write a
program that allows the user to enter an amount in dollars, and then displays this value
converted to these four other monetary units.
5. If you have two fractions, a/b and c/d, their sum can be obtained from the formula
Write a program that encourages the user to enter two fractions, and then displays their
sum in fractional form. (You don’t need to reduce it to lowest terms.)
The interaction with the user might look like this:
Enter first fraction: 1/2
Enter second fraction: 2/5
Sum = 9/10
6. An electricity board charges the following rates to domestic users to discourage large
consumption of energy. For the first 100 units Rs. 1.50 per unit For the next 200 units Rs.
3.00 per unit Beyond 300 units Rs. 5.00 per unitAll users are charged a minimum of Rs.100. If
the total cost exceeds Rs.250, then an additional surcharge of 15% is added. Write a program
to read the names of users and number of units consumed and print out the charges with
names.
Tutorial 3(25.09.2020)
1. Assume that you want to generate a table of multiples of any given number. Write a
program that allows the user to enter the number and then generates the table, formatting
it into 10 columns and 20 lines. Interaction with the program should look like this (only the
first three lines are shown):
Enter a number: 7
7 14 21 28 35 42 49 56 63 70
77 84 91 98 105 112 119 126 133 140
147 154 161 168 175 182 189 196 203 210
2. Write a temperature-conversion program that gives the user the option of converting
Fahrenheit to Celsius or Celsius to Fahrenheit. Then carry out the conversion. Use floating-
point numbers. Interaction with the program might look like this: Type 1 to convert Fahrenheit
to Celsius, 2 to convert Celsius to Fahrenheit: 1 Enter temperature in Fahrenheit: 70 In
Celsius that’s 21.111111
3. Create the equivalent of a four-function calculator. The program should ask the user to enter
a number, an operator, and another number. (Use floating point.) It should then carry out the
specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers.
Use a switch statement to select the operation. Finally, display the result. When it finishes the
calculation, the program should ask whether the user wants to do another calculation.
4. Create a four-function calculator for fractions. Here are the formulas for the four arithmetic
operations applied to fractions:
• Addition: a/b + c/d = (a*d + b*c) / (b*d)
• Subtraction: a/b - c/d = (a*d - b*c) / (b*d)
• Multiplication: a/b * c/d = (a*c) / (b*d)
• Division: a/b / c/d = (a*d) / (b*c)
•The user should type the first fraction, an operator, and a second fraction. The program should
then display the result and ask whether the user wants to continue.
Tutorial 4(09.10.2020)
1. Write a function called circarea() that finds area of circle.It should take an argument of type
float and return an argumentof the same type .Write a main function that gets a readius
value from the user ,calls circarea() and display the result.
2. Raising a number n to a power ‘p’ is the same as multiplying n by itself p times.Write a
function called power() that takes a double value for n and an int value for p and the result is
returned as a double value.Use a default argument of 2 for p so that if this argument is
omitted ,the number ‘n’ will be squared ,Write a main() function that gets the values from
the user to test this function.
3. Write a function zeroSmaller() that is passed two integers by reference and then sets the
smaller of the two numbers to zero.Write a main program to exercise this function.
4. Write a function that takes two distance values as arguments and returns the larger one.
Include a main() program that accepts two distance values from the user ,compares them
and displays the larger.
5. Addition of two points using a structure
6. Program to input different parts of telephone code and display output using structure
7. Print Pattern
1
1 2 3
1 2 3 4 5
8. Print Pattern
*
* * *
* * * * *
9. Program to create a structure to add two distances that are given in feet and inches
Tutorial 5(23-10-2020)
*****
3. Create a class called time that has seperate int member data for
hours,minutes,seconds.Include constructors to initialise the data to 0 and to fixed value.
Also include nesscesary member functions to display the time in 11:59:59 format and
function to add object of time passed as argument.
4. Create a class STUDENT declare data members as USNnumber(int type),semester(int
type),six subject marks.
Declare a member function to read(),percent() and display.Calculate the percentage of a
student using percent(),
and based on percentage assign a class to a student with the following conditions
if percentage>=75% - FCD
between 60 to 74% - FC
between 50 to 59% - SC
below 50%- FAIL
Make this record for 10 students
5. averaging of array elements
6. Demonstrattion of Multi-dimensional array
7. Program to show use of static data members
8. Function Overloading for area of triangle,rectangle,circle
9. Write a class “rectangle” containing two data items “length” and breadth “ and four
functions setdata(), getdata(),displaydata() and area () to set the length and breadth,
to get the user inputs, to display and to find the area of the rectangle respectively.Also write
a main program which declares the objects and uses the member functions of the class.
10. Create a four – function calculator for fractions. The user should type the first fraction, an
operator, and a second fraction. The program should then display the result and ask
whether the user wants to continue. The functions should be called using fadd( ), fsub( ),
fmul( ), and fdiv( ). Each of these functions should take two arguments of type struct
fraction, and return an argument of the same type.
Tutorial 6(06-11-2020)
1. Write a function called reverseit() that reverses a C-string(an array of charecter).Use a for loop
that swaps the first and last last charecter,then the second and last but one character and so on
.The string should be passed to reverseit() as an argument.Write a program to get a string from
the user ,call reverseit(), and print out the result .Use an input method that allows embedded
blanks.
2. Create a class called employee that contains a name (an object of class string) and an employee
number (type long).Include a member function called getdata() to get data from the user for
insertion into the object and another function called putdata() to display the data.Assume that
name has no embedded blanks.Write a main() program to excercise this class.It should create an
array of type employee and then invite the user to input data for up to 100 employees.Finally, it
should print out data for all the employees.
3. Write a program that calculates the average of upto 100 English distance create an array of
objects of the class Distance.
4. Start with a program that allows the user to input a number of integers and then stores them in
an int array.Write a function called maxint() that goes through the array ,element by
element,looking for the largest one .The function should take the address of the array and the
number of elements in it as arguments.And return the index number of the largest element.The
program should call this function and then display the largest element and its index number
6. Write a program to compare two STRING data type ,If the two values are equal print that they
are equal otherwise print they are not equal.
7. Implementing a stack with safe push and safe pop operations
Tutorial 7(13-11-2020)
Tutorial 8(20-11-2020)
Tutorial 9(27-11-2020)
Tutorial 10(04-12-2020)
#include <iostream>
////////////////////////////////////////////////////////////////
public:
{ cout<<"Base\n"; }
};
////////////////////////////////////////////////////////////////
public:
void show()
};
////////////////////////////////////////////////////////////////
public:
void show()
};
int main()
return 0;