0% found this document useful (0 votes)
139 views4 pages

C++ Lab: Advanced Data Types

This document provides instructions and questions for Lab 4 on advanced data types in C++ programming. It contains 4 questions: [1] Rewrite code with an enum error and output the result, [2] Assign values to the enum and output the result, [3] Describe a program that uses a union, [4] Write a program that calculates two numbers using data hiding and encapsulation. The student is asked to answer all questions and submit their responses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views4 pages

C++ Lab: Advanced Data Types

This document provides instructions and questions for Lab 4 on advanced data types in C++ programming. It contains 4 questions: [1] Rewrite code with an enum error and output the result, [2] Assign values to the enum and output the result, [3] Describe a program that uses a union, [4] Write a program that calculates two numbers using data hiding and encapsulation. The student is asked to answer all questions and submit their responses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CNS3101: C++ Programming

Semester 1 2022/2023
LAB 4: Advances Data Types

INSTRUCTION: Please answer all the lab exercises.


Please submit this task through Putrablast.
(Due date: 5 Dec 2022)

Lab 4: Student Generated Code Exercises

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

You might also like