Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Lab Sheet

The document contains 15 programming problems related to C++ concepts like arrays, loops, functions, structures, and recursion. The problems cover tasks like temperature conversion, ATM transactions, calculators, array operations, searching, sorting, recursion, structures, and more. The user is expected to write C++ code to solve each problem by taking input, performing calculations, and returning output as specified in each problem description.

Uploaded by

omarsarwt590
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Lab Sheet

The document contains 15 programming problems related to C++ concepts like arrays, loops, functions, structures, and recursion. The problems cover tasks like temperature conversion, ATM transactions, calculators, array operations, searching, sorting, recursion, structures, and more. The user is expected to write C++ code to solve each problem by taking input, performing calculations, and returning output as specified in each problem description.

Uploaded by

omarsarwt590
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab Sheet

Computer Programming
1- Write a temperature conversion program that gives the user the option of
converting a value of temperature to Celsius and Fahrenheit scales of temperature.

2- Write a program that takes balance of a user’s account as input. It should then
ask the user how much amount he wants to withdraw from his account. The program
should take this amount as input and deduct from the balance. Similarly it should ask
the user how much amount he wants to deposit in his account. It should take this
amount as input and add to the balance. The program shall display the new balance
after amount has been withdrawn and deposited.

Note: Your program should have a check on balance and amount being withdrawn.
Amounts greater than balance cannot be withdrawn i.e. balance cannot be negative.

PAGE 0
3- Write a program which takes two numbers as input from user and determines
which is the larger of the two numbers. The Program should also tell which of the
entered numbers is even or odd.

4- You need to design a calculator that performs four basic arithmetic operations.
You will write a program that takes two numbers as input from the user. It then
displays a list of arithmetic operations. The user selects one operation and the
program displays the result of the corresponding operation. The program should also
display which of the two input numbers is greater and which is smaller. Use do-while
loop. Interaction with the program might look like the following:

5- At its closest point to Earth Mars is approximately • At its closest point to


Earth, Mars is approximately 34,000,000 miles away. Assuming there is
someone on Mars that you want to talk with, what is the delay between the
time a radio signal leaves Earth and the time it arrives ? on Mars?
6- Write a program that takes marks of 10 students as input. It calculates the
class average and displays it on the screen. Interaction with the program
might look like this. Use while loop.

PAGE 1
7- Write a program that repeatedly asks the user to enter two money amounts
expressed in pounds. The program should then add the two amounts and
display the answer in pounds. The program should then convert the amount
in Rupees. (Set conversion rate: 1£=120.33 rupees). Display the answer in
Rupees. Use a do-while loop that asks the user whether the program should
be terminated.

8- An aircraft system is designed which checks speeds and monitors various


functions of the aircraft during the flight. Warnings and errors are generated
if any fault develops during the flight. The system is coded in a manner that
if 100 is entered as input it indicates “normal speed range”, if 101 is entered it
gives “over-speed warning” indicating that aircraft is over-speeding. If 88 is
entered, it indicates “Low Oil Pressure” and if 187 is entered it indicates
“Engine Failure”. Use switch statement to implement this logic.

9- Write a C++ program to find the sum and average of one dimensional integer
array.

PAGE 2
10- Take 10 integer inputs from user and store them in an array. Now, copy all the
elements in another array but in reverse order.

11- Write a program to find the sum and product of all elements of an array.

12- Write a program to print sum, average of all numbers, smallest and largest
element of an array and sort array element in descending order.

13- Write a program that asks the user to type 10 integers of an array and an
integer s. then search the value s from the array and display the value of s if it
is found in the array otherwise print sorry not found.

14- Explain the functionality of following function:

int fun1(int x, int y)


{
if(x == 0)
return y;
else
return fun1(x - 1, x + y);
}

15- What is the output of the following code?

void my_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
}

16- Look at the following code:


struct Town {
string townName;
string countyName;
double population;
double elevation;

PAGE 3
};
Town t = {"Canton", "Haywood", 9478 };
A) what is t.townName? B) what is t.countyName?
C) what is t.population? D) what is t.elevation?

17- Look at the following structure declaration:


struct Point {
int x;
int y;
};
Write statements that
A) Define a Point structure variable named center.
B) Assign 12 to the x member of center
C) Assign 7 to the y member of center
D) Display the contents of the x and y members of center
18- Which of the following is a properly defined struct?
A. struct {int a;}
B. struct a_struct {int a;}
C. struct a_struct int a;
D. struct a_struct {int a;}
19- Find factorial of integer number enter by the user, by using recursion
technique.
20- A record system is needed to hold information on employees in a faculty. The
basic employee information is defined as: the employee Name, the employee
id and the employee Salary. Write a C++ Employee structure definition with
the appropriate fields to cover the above requirements.[ note: user enter
data].

PAGE 4
1- C++ Program to Display Factors of a Number
#include <iostream>
using namespace std;
int main()
{
int n, i;
cout << "Enter a positive integer: ";
cin >> n;
cout << "Factors of " << n << " are: " << endl;
for(i = 1; i <= n; ++i)
{
if(n % i == 0)
cout << i << endl;
} return 0;
}

CHECK PRIME NUMBER


#include <iostream>
using namespace std;

int main()
{
int n, i;
bool isPrime = true;

cout << "Enter a positive integer: ";


cin >> n;

for(i = 2; i <= n / 2; ++i)


{
if(n % i == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
cout << "This is a prime number";
else
cout << "This is not a prime number";
return 0;
}

PAGE 5

You might also like