Lab Manual # 12: Title: C++ Nested Structures
Lab Manual # 12: Title: C++ Nested Structures
Lab Manual # 12: Title: C++ Nested Structures
Lab Manual # 12
CLO: CLO-1
Lab Submission[10] 0 1 2 3 4 5
Completeness & Correctness
Required Conclusion & Results
No of Checks
SUB TOTAL
TOTAL SCORE
______________________
Course Instructor / Lab Engineer
When a structure contains another structure, it is called nested structure. For example,we have
two structures named Address and Employee. To make Address nested to Employee, we have
to define Address structure before and outside Employee structure and create an object of
Address structure inside Employee structure.
Syntax:
struct structure1
{
----------
----------
};
struct structure2
{
----------
----------
structure1obj;
};
Example:1Nested Structure
#include<iostream>
Using namespace std;
struct Address
{
charHouseNo[25];
char City[25];
charPinCode[25];
};
struct Employee
{
int Id;
char Name[25];
float Salary;
Address Add;
};
void main()
{
cout<<"Details of Employees";
cout<<"Employee Id : "<<E.Id<<endl;
cout<<"Employee Name : "<<E.Name<<endl;
cout<<"Employee Salary : "<<E.Salary<<endl;
cout<<"Employee House No : "<<E.Add.HouseNo<<endl;
cout<<"Employee City : "<<E.Add.City<<endl;
cout<<"Employee House No : "<<E.Add.PinCode<<endl;
P-1: Write a program that uses two structures Results and Record. The Result structure stores
marks and grade, Record structure stores roll number and a Result type. The program declares
a variable of type Record, inputs roll number, marks and grade. It finally displays these values
on the screen.
Your Code:
P-2 Write a program that uses three structures Dimension, Results and Rectangle. The
Dimension structure stores length and width, Result structure stores area and perimeter and
Rectangle stores two variables of Dimension and Results. The program declares a variable of
type Rectangle, inputs length and width, calculates area and perimeter and then display the
results
Your Code:
P-3 Write a program that uses two structures GradeRec and StudentRec. The GradeRec
structure stores percentage and grade,StudentRec stores information of student. Declare a
variable of GradeRec in StudentRec structure.The program should output each student’s
information followed by the percentage and the relevant grade. It should also find and print the
lowest test score and the name of the student having the lowest test score.
Your Code:
Comments: