0% found this document useful (0 votes)
8 views2 pages

Lab Exercise 3

Uploaded by

palakgoyal0506
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Lab Exercise 3

Uploaded by

palakgoyal0506
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Jaypee University of Engineering and Technology, Guna

B.Tech. (Semester II)


Object Oriented Programming Lab (CS202)
Lab Exercise 3

1. 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 (two values a and b), an operator, and a second
fraction (two values c and d). The program should then display the results in fraction i.e.
(Numerator/ denominator).

2. Write a menu driven program (using switch-case) to create a database of student names
and perform the following operations using array of character pointers and dynamic
memory allocation.

a. To insert a student name

b. To delete a name (Show Error message if zero names are there in database)

c. To print the names

Note: your program should keep on showing above three options until user enters ‘N’.

3. Given an array A of size N-1 and given that there are numbers from 1 to N with one
element missing; Write program to find the missing number.

Test case 1: Given array: 1 2 3 5; missing element is 4.


Test case 2: Given array: 1 2 3 4 5 6 7 8 10; missing element is 9.

4. Write C++ Program to swap two variable using reference variables.

5. Write a function that finds the minimum and the maximum value in an array of N integers.
Inputs to the function are the array of integers, an integer variable containing the length of
the array and references to integer variables that will contain the minimum and the
maximum values. The function prototype is:

void minmax( int array[], int length, int& min, int & max);
6. Write a program to find Kth smallest and Kth largest element in an unsorted array.

Sample Test Case1

Input:
A[]=4, 5, 60, 70, 33, 44
K=2
Output:
2nd smallest number is 5 and 2nd largest number is 60

Sample Test Case2

Input:
A[]=2, 46, 56, 68, 3, 34, 489, 457, 4545, 100
K=5
Output:
5th smallest number is 56 and 5th largest number is 68

7. Solve the following questions from Hackerrank:

a. https://www.hackerrank.com/challenges/pointer-in-c/problem?isFullScreen=true

b. https://www.hackerrank.com/challenges/students-marks-
sum/problem?isFullScreen=true

c. https://www.hackerrank.com/challenges/too-high-
boxes/problem?isFullScreen=true

You might also like