Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab Manual # 12: Title: C++ Nested Structures

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Lab # 12 – Programming Fundamentals (CPE-121)

Lab Manual # 12

Title: C++ Nested Structures

CLO: CLO-1

Student Name: Class Roll:

Subject Teacher : Engr. Muhammad Baqer


Lab Engineer : Engr. Abdul Rehman
Lab Performed In : Networking Lab (CPED)

LAB POINTS SCORE


Lab Performance [10] 0 1 2 3 4 5
Lab Participation
Lab Activity Completion on the Same Day

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

Version 1.0 Department of Computer Engineering UCE&T BZU Multan


Lab # 12 – Programming Fundamentals (CPE-121)
Nested Structure

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()
{

Version 1.0 Department of Computer Engineering UCE&T BZU Multan


Lab # 12 – Programming Fundamentals (CPE-121)
int i;
Employee E;

cout<<"Enter Employee Id : "<<endl;


cin>>E.Id;
cout<<"Enter Employee Name : "<<endl;
cin>>E.Name;
cout<<"Enter Employee Salary : "<<endl;
cin>>E.Salary;
cout<<"Enter Employee House No : "<<endl;
cin>>E.Add.HouseNo;

cout<<"Enter Employee City : "<<endl;


cin>>E.Add.City;
cout<<"Enter Employee House No : "<<endl;
cin>>E.Add.PinCode;

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;

Version 1.0 Department of Computer Engineering UCE&T BZU Multan


Lab # 12 – Programming Fundamentals (CPE-121)

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:

Paste your output here

Version 1.0 Department of Computer Engineering UCE&T BZU Multan


Lab # 12 – Programming Fundamentals (CPE-121)

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:

Version 1.0 Department of Computer Engineering UCE&T BZU Multan


Lab # 12 – Programming Fundamentals (CPE-121)
Paste your output here

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:

Version 1.0 Department of Computer Engineering UCE&T BZU Multan


Lab # 12 – Programming Fundamentals (CPE-121)
Paste your output here

Comments:

Version 1.0 Department of Computer Engineering UCE&T BZU Multan

You might also like