0% found this document useful (0 votes)
32 views

NAME: Arslan Sohail ROLL NO: L15-4546 Section: El-1B

This document contains a lab report submitted by Arslan Sohail with roll number L15-4546 from section EL-1B. The report discusses nested structures and pointers to structures. It describes declaring a nested structure with members like name within another structure called facultyMember. It also describes declaring an array of structures and copying data between structures. The conclusion is that data from one structure can be accessed in another nested structure and data can be copied between variables and structures.

Uploaded by

Arslan Sohail
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

NAME: Arslan Sohail ROLL NO: L15-4546 Section: El-1B

This document contains a lab report submitted by Arslan Sohail with roll number L15-4546 from section EL-1B. The report discusses nested structures and pointers to structures. It describes declaring a nested structure with members like name within another structure called facultyMember. It also describes declaring an array of structures and copying data between structures. The conclusion is that data from one structure can be accessed in another nested structure and data can be copied between variables and structures.

Uploaded by

Arslan Sohail
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME: Arslan Sohail

ROLL NO: L15-4546


SECTION: EL-1B

Programming Fundamentals

LAB REPORT # 5

SUBMITTED TO: Sir Muhammad Umar Bashir

DATE: Tuesday, June 15, 2021


Introduction:
Nested Structures are structures within a structure. Declaring a structure within a structure as we
declare member in a structure. Pointers to a structure is a member to a structure. Suppose A is
nested within B then A can be accessed with object of A but B can only be accessed using object
of A and member of A using dot operators.

Objective:
There were following two objectives in the last lab:
1. Nested Structures
2. Pointers to Structures

Design/Procedure:
Question 1:
We declare a struct ‘name’ having two members ‘first_name’ & ’last_name’ nested in another
struct ‘facutyMember’ and declare three members ‘id’, ‘student’ and ‘designation’ into struct
‘facutyMember’ then we declare ‘fm’ as an object of ‘facutyMember’. We implemented three
functions can call them in main, in the first function we inset data into three members of struct in
the second struct we print data of members of struct and in the third function we declare array of
data type ‘facutyMember‘ named ‘fm[]’ , then we sort array of object with respect of ID number.

Question 2:
We declare another struct named university and an object named ‘myUni’ , members of struct
are ‘nameU’, ‘address’ and array of data type ‘facutyMember’ named ‘arr[]’.
We hardcoded the data into ‘nameU’, ‘address’. Then we declare insert data into array of fm[]
and then copy that data into arr[]. Then print ‘nameU’, ‘address’ and arr[].

Application:
Nested loop is useful when you want to use data of one structure in another structure.

Conclusion:
We conclude that data of one structure can be accessed into another structure by nesting it in to
the other one. Data of an array can be copied into structure as we copy data of one variable into
another.
POST LAB:
#include <iostream>
#include <string>
using namespace std;

struct Book_List
{
int Book_Code;
string Book_name;
string Subject;
int Book_Price;
int Edition;
}B[3];
struct Record
{
int ID;
string name;
}R;

void Record();

int main()
{
Record();

system ("pause");
return 0;
}
void Record()
{
cout << "Enter ID" << endl;
cin >> R.ID;

cout << "Enter Name" << endl;


cin >> R.name;

for (int i = 0; i < 3; i++)


{
cout << "===============" << endl;

cout << "Enter Book_Code" << endl;


cin >> B[i].Book_Code;

cout << "Enter Book_name" << endl;


cin >> B[i].Book_name;

cout << "Enter Subject" << endl;


cin >> B[i].Subject;

cout << "Enter Book_Price" << endl;


cin >> B[i].Book_Price;

cout << "Enter Edition" << endl;


cin >> B[i].Edition;

cout << endl;


}}

You might also like