Professional Documents
Culture Documents
C++ Sample Lab Question
C++ Sample Lab Question
Semester 1 2022/2023
LAB 4: Advances Data Types
Q1: Please rewrite the following code and correct the error. What is the
output?
#include <iostream>
using namespace std;
enum favourite { flower, vehicles, food, fruit};
int main ()
{
favourite fav;
w = food;
cout << fav << w+1;
return 0;
}
1
Q2: Based on Q1, assign the value flower with 7, vehicles with 19, food
with 1 and fruit with 2. What is the output?
Q3: Search for a program that uses Union. Describe how the codes work.
2
In the above code, exp2 variable is assigned an integer (34). But by being of char
type, the value is transformed through coercion into its char equivalent
(“).
Q4: Write a program that uses data hiding and encapsulation to calculate
two numbers. The proposed program could do any mathematical
operation, such as addition, subtraction, division or multiplication.
3
4