You are on page 1of 7

National University

Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

CL-217
Object Oriented Programming
Lab 1
Objectives:
• Revision of all concepts of programming fundamentals
• Control Structures
• Repetitive Structure including nested method
• Function
• Array
• File handling

Note: Carefully read the following instructions (Each instruction contains a weightage)

1. There must be a block of comments at start of every question's code by students; the block should
contain brief description of the functionality of the code.
2. Comment on every function about its functionality
3. Use understandable name of variables.
4. Proper indentation of code is essential
5. Write a code in C++ language.
6. Make a Microsoft Word file and paste all of your C++ code with all possible screenshots of every
task outputs in MS word and do not submit .cpp file with word file.
7. First think about statement problems and then write/draw your logic on copy.
8. After copy pencil work, code the problem statement on MS Studio C++ compiler.
9. At the end when you have done your tasks, attached C++ created files in MS word file and make
your submission on Microsoft Teams. (Make sure your submission is completed).
10. Please submit your file in this format 19F1234_A1.
11. Do not submit your assignment after the deadline.
12. Add your name in Footer to score Bonus Marks (2)
13. Do not copy code from any source otherwise you will be penalized with negative marks.
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Problem: 1 | Control structure (If else)

Suppose that x, y, and z are int variables, and a = 100, b = 105, and c = 30. Write a single C++ code to
determine whether the following expressions evaluate to true or false.

1. (a > b) || (c < d) && (a== c*3)


2. (a > b) && ((a < c) || (c == 10))
3. (a <= b - 2) && (b >= c) || (c - 2! = 20)
4. a<= 5 || b < 15

Problem: 2 | Control structure (If else)

Write a program to calculate the electricity bill of FAST-NU Faisalabad. The rates of electricity per unit
are as follow:

1. If the units consumed are equal or less than 100, then the cost is Rs. 9.5/- Per unit and no
surcharge of bills is added.
2. If units consumed are within 101-300, then the cost is Rs. 10.5/- per unit and a surcharge of 30%
of bill is added.
3. If units consumed more than 300, then the cost is Rs. 15/- per unit and a surcharge of 40 % is
added.

Keep in mind that you should take values from user in the current and previous reading forms.

For example, I have reading of month January 3466 units and counting for February. I will enter previous
reading 3466 and the current reading will be 3600 for February. So, I get (3600-3466= 144units).

Note:

• The answer should be as precise as you can.


• Means that use int where int use and use float/double where use.
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Problem: 3 |pointers

Write a program which declares an array of 5 numbers. Initialize the array with 3, 9, 1, 15, 3. Now
use the

• Increment operator
• Decrement operator

in pointers to print the address and values of each index. Also compare all values of pointers

and display if some values are equal.

Problem: 4|Functions

The Fibonacci series

0, 1, 1, 2, 3, 5, 8, 13, 21,…

(a) Write a nonrecursive function fibonacci(n) that uses type int to calculate the nth Fibonacci number.

(b) Determine the largest int Fibonacci number that can be printed on your system. Modify the program
of part (a)to use double instead of int to calculate and return Fibonacci numbers and use this modified
program to repeat part(b).

Problem: 5|Functions

Write a function that takes an integer value and returns the number with its digits reversed. For
example, given the number1234, thefunctionshouldreturn4321
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Problem: 6|Functions

Write a c++ program that creates a file and stores following operation in the file
1. Add
2. Subtract
3. Multiply
4. Divide
5. Square root
Ask user to input two number. Now read above operations from file and display on console.
Now get choice from user which operation user want to perform. After operation is applied store the
result in same file by using append operation.

Problem:7 |Pointers

Write a c++ program, you have an array of double and a double type of pointer
double balance[5] = {1000.0, 2.01, 3.4, 17.0, 50.40};

double *p;

p = balance;

Now you have to print the array using p pointer.

Problem: 8|pointers

Write a C++ program where you have two integer variables


int firstvalue = 5, secondvalue = 15;

and two pointers

int * p1, * p2;

You have to perform the following steps


• // p1 = address of firstvalue
• // p2 = address of secondvalue
• // value pointed by p1 = 10
• // value pointed by p2 = value pointed by p1
• // p1 = p2 (address of pointer is copied)
• // value pointed by p1 = 20
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

• // print firstvalue, secondvalue

And comment like above after each step


Values will be p1=10 and p2=20

Problem: 9|Pointer

Take two numbers from user as input in pointer and perform following operations on
variables using pointers.

1. Addition
2. Subtraction
3. Multiplication
4. Division.
5. Mod
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

You might also like