You are on page 1of 4

Chandigarh University, Gharuan

Paradigms of Computer Programming and
Subject Code: CSP L T P C
C++Lab
157
Total Contact Hours : 30 Hours
0 0 4 2
Common to all Branches of First Year
Marks-100
Internal-60 External-40
Course Objectives
 To understand the concept of the various Programming Paradigms
 To apply different programming languages for modeling real world problems.
Unit Course Outcomes
Understand the various paradigms of computer programming
Identify the strengths and weaknesses of different programming paradigms
I-III Students will demonstrate basic experimental skills for differentiating between
object oriented and procedural programming paradigms and the advantages of
object oriented programs.

UNIT-I
Program based on basics datatypes and operator in C++.
i. 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.
ii. Convert temperature from degrees Celsius to degrees Fahrenheit by multiplying by 9/5 and
adding 32. Write a program that allows the user to enter a floating-point number
representing degrees Celsius, and then displays the corresponding degrees Fahrenheit.
Program based on conditional constructs.
i. The normal speed of a vehicle is less than 65kmph. If entered speed is less than 65kmph you
can print within speed limit otherwise over speed limit.
ii. Create the equivalent of a four-function calculator. The program should request 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 if the user wants to do another
calculation. The response can be ‘y’ or ‘n’. Some sample interaction with the program might
look like this:
Program based on looping.
i. Write a program that calculates how much money you’ll end up with if you invest an
amount of money at a fixed interest rate, compounded yearly. Have the user furnish the

(This member should apply to the class as a whole. It should create an array of type employee. as each object is created. and then generates the table. Write a program that allows the user to enter the number. iv. That is. ii. and then invite the user to input data for up to 100 employees.) So the number of possible arrangements of six guests in four chairs is 6*5*4*3. (The last two will have to stand. but your table seats only four. Assume the name has no embedded blanks. iii. type float). Include a member function called getdata() to get data from the user for insertion into the object.43 rupees. the number of years. it should print out the data for all the employees. Suppose you give a dinner party for six guests. And also calculate total compensation. you will have 5124. Assume you want to generate a table of multiples of any given number. Finally.5 At the end of 10 years. the second 2. Write a program that calculates the number of possible arrangements for any number of guests and any number of chairs. To do this. Create a class that includes a data member that holds a “serial number” for each object created from the class. Program to generate the Fibonacci series up to user specified limit. What keyword specifies this?) Then. initial amount. and so on. store it in three variables of type struct employee. ii. you’ll need another data member that records a count of how many objects have been created so far. the first object created will be numbered 1. iii. i. and the yearly interest rate in percent. Write a main() program to exercise this class. Any of the remaining four can sit in the third chair. Create a structure called employee that contains two members: an employee number (type int) and the employee’s compensation (in dollars. formatting it into 10 columns and 20 lines. In how many ways can four of the six guests arrange themselves at the table? Any of the six guests can sit in the first chair. Program based on the concept of structure and class. and any of the remaining three can sit in the fourth chair. Create a class called employee that contains a name (an object of class string) and an employee number (type long). Some interaction with the program might look like this: Enter initial amount: 3000 Enter number of years: 10 Enter interest rate (percent per year): 5. and another function called putdata() to display the data. Ask the user to fill in this data for three employees. its constructor can examine this count member variable to determine the appropriate serial . not to individual objects. Any of the remaining five can sit in the second chair. and then display the information for each employee. which is 360.

Once the numbers are stored in the array. to initialize it to an int value. Create a class called time that has separate int member data for hours. Each of these three classes should have a getdata() function to get its data from the user at the keyboard.Call the class Int(note different spelling). Another member function should display it. The final member function should add two objects of type time passed as arguments. in 11:59:59 format. Imagine a publishing company that markets both book and audiocassette versions of its works. which adds a playing time in minutes (type float). Include member functions to initialize an Int to 0. and another should initialize it to fixed values. Use pointer notation wherever possible. Then it should add the two initialized values together. Create a class publication that stores the title (a string) and price (type float) of a publication. and so on. Finally it should display the value of this third variable. They should respond I am object number 2. Write a program that reads a group of numbers from the user and places them in an array of type float. the program should average them and print the result. and seconds. Program based on inheritance i. leaving the result in the third time variable. Then write a main() program that creates three objects and queries each one about its serial number. and tape. Write a program that exercises this class by creating two initialized and one uninitialized Int values. Make appropriate member functions const. number for the new object. . UNIT-II Program based on polymorphism. Program based on constructor and destructor i. i. Create a class that imitates part of the functionality of the basic data type int. UNIT-III Program based on pointers and dynamic memory allocation. and a putdata() function to display its data. and then displaying this result. The only data in this class is an int variable. minutes. Add a member function that permits an object to report its own serial number. From this class derive two classes: book. A main() program should create two initialized time objects (should they be const?) and one that isn’t initialized. to display it (it looks just like an int). which adds a page count (type int). One constructor should initialize this data to 0. adding these two initialized values and placing the response in the uninitialized value. and use operator overloading to add two Int values. i.

. ii. Write a program to store the information of about 5 students in a file and read the contents and print them on screen. Write a program to demonstrate the use of new and delete operators. i. Program based on exception handling and File Handling. Perform exception handling for Divide by zero Exception.ii.