[go: up one dir, main page]

0% found this document useful (0 votes)
83 views7 pages

Lab 2.

This document contains 10 programming problems to evaluate expressions, calculate values based on variables, find areas of shapes, display data type sizes, and demonstrate use of compound operators in C++. Code for each problem is saved in the file E:\usman.exe. Problems include calculating the value of an expression using order of operations, writing programs to evaluate expressions with variables, calculating the area of a square and sphere, showing max/min limits of data types, finding byte sizes of variables, writing equivalent expressions for compound operators, declaring and manipulating character and integer variables, and using auto keyword with compound assignment operators.
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)
83 views7 pages

Lab 2.

This document contains 10 programming problems to evaluate expressions, calculate values based on variables, find areas of shapes, display data type sizes, and demonstrate use of compound operators in C++. Code for each problem is saved in the file E:\usman.exe. Problems include calculating the value of an expression using order of operations, writing programs to evaluate expressions with variables, calculating the area of a square and sphere, showing max/min limits of data types, finding byte sizes of variables, writing equivalent expressions for compound operators, declaring and manipulating character and integer variables, and using auto keyword with compound assignment operators.
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/ 7

RollNo SU73-ADCSM-F22-020

033

Name MALIK MUSHTAQ AHMED


M Usman
Class ADP-CS (semester 1)
2.1.1. Expression Evaluation
Evaluate the following expression in its order of precedence:

10 * (24 / ( 5 – 2 ) ) + 13

Step Operator Reduced expression

1 (5-2) 10*(24/(3))+13

2 (24/3) 10*(24/3)+13

3 10*8 10*8+13

4 80+13 80+13

Result: 93

2.1.2. Program No 2
Write a program to determine the value of following expression, where a =1.5, b=1.1, c=2.89, d=9.0
2d+4ab*c+5a

Save the result in variable e, and then output.

Code of Program No 2:
E:\usman.exe

2.1.3. Program No 3
Write a program to calculate and print the area of a square.

E:\usman.exe

2.1.4. Program No 4
Write a program in C++, which takes radius from the user and calculate the area of sphere i.e.

Area= 4pr2
Hint p=3.1416
Area= 4*3.1416*r*r
E:\usman.exe

2.1.5. Program No 5
Write a program that include limits header file, and show the max and min limits of all data types.

E:\usman.exe

2.1.6. Program No 6

Write a program to find number of bytes occupied by various data types using the sizeof operator. int

a;char b;float c;long int d;bool e;unsigned int j;unsigned long k;


E:\usman.exe

2.1.7. Program No 7

Write equivalent expressions of following compound assignment operators


Operator Equivalent expression

A += 10 A=A+10

A-= 10 A=A-10

A *= 10 A=A*10

A /= 10 A=A/10

A %= 10 A=A%10

2.1.8. Program No 8
Write a C++ program that declares and initializes two-character variables. Add the characters and display
their result.
2.1.9. Program No 9
Write a C++ program that declares two integer variables, two-character variables. Initializes the integer
variables, and assign the integer variables to character variables. Display the character variables. Also,
display the size of all variables using the size of operator.

E:\usman.exe

2.1.10. Program No 10

Write a Program in C++ that declares and initializes an integer variable. Increment and decrement the
variable by 5 using compound assignment. Then multiply and divide the variable by 2 using compound
assignment. Display the result at every level. Use auto keyword to declare the variable.
E:\usman.exe

You might also like