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

DSA - Lab6 Strcture & Pointers

This document is a lab manual for a data structures and algorithms course. It provides instructions and exercises for students to complete an in-lab session on pointers and structures in C++. The objectives are to understand and apply pointers and structures to represent data. Students are given exercises to create a nested structure to represent a student record with name, age, and roll number, and to modify the program to access the structure using pointer variables. A third exercise asks students to create a structure for employee data including name, ID, and salary, and to apply bubble sort and linear search algorithms to the employee data.

Uploaded by

51b48265a74f87
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

DSA - Lab6 Strcture & Pointers

This document is a lab manual for a data structures and algorithms course. It provides instructions and exercises for students to complete an in-lab session on pointers and structures in C++. The objectives are to understand and apply pointers and structures to represent data. Students are given exercises to create a nested structure to represent a student record with name, age, and roll number, and to modify the program to access the structure using pointer variables. A third exercise asks students to create a structure for employee data including name, ID, and salary, and to apply bubble sort and linear search algorithms to the employee data.

Uploaded by

51b48265a74f87
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

DEPARTMENT OF COMPUTER SCIENCE


http://web.uettaxila.edu.pk

Lab Manual 06
CS201: Data Structure and Algorithms
Class: BSCS-2k22
Lab 6: Strcture and pointers

Instructors:
Mr. Awais Mehmood
[email protected]
&
Mr. M. Faheem Saleem
[email protected]

CS201: Data Structures and Algorithms Page 1


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
DEPARTMENT OF COMPUTER SCIENCE
http://web.uettaxila.edu.pk

Lab Manual 6
Introduction
This lab is about the pointers and structures.
Objectives
The objectives of this session is to recall and understand the usage of pointers and structures in
C++ and apply these to data strctures.
Tools/Software Requirement
Dev C++
Goals for today’s lab:

• Understanding pointers and structures.

CS201: Data Structures and Algorithms Page 2


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
DEPARTMENT OF COMPUTER SCIENCE
http://web.uettaxila.edu.pk

Exercise
Write a C++ program to make a structure of a student consisting of integer age, char name and
structure roll number that further divides into department, session, registration number and
degree. Set and display all the values from main function and display the record on screen to
present the access of structure within structure.
Solution
#include<iostream>
using namespace std;
struct student{
int age;
char name[15];
struct roll_no{
char dep[5];
int session;
int no;
char degree[5];
}rn;
};
int main()
{
student s1;
cout<<"eneter name: "<<endl;
cin>>s1.name;
cout<<"enter age: "<<endl;
cin>>s1.age;
cout<<"enter roll no: "<<endl;
cout<<"enetr dep: "<<endl;
cin>>s1.rn.dep;
cout<<"enter session: "<<endl;
cin>>s1.rn.session;
cout<<"enter number: "<<endl;
cin>>s1.rn.no;
cout<<"enter degree: "<<endl;
cin>>s1.rn.degree;
cout<<"name is: "<<s1.name<<endl;
cout<<"age is: "<<s1.age<<endl;
cout<<"roll no is: "<<endl;
cout<<"deartment: "<<s1.rn.dep<<endl;
cout<<"session is: "<<s1.rn.session<<endl;
cout<<"degree is: "<<s1.rn.degree<<endl;
cout<<"number is: "<<s1.rn.no<<endl;
}

CS201: Data Structures and Algorithms Page 3


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
DEPARTMENT OF COMPUTER SCIENCE
http://web.uettaxila.edu.pk

Output:

Exercise 2
Modify above stated program by accessing structure using pointer type variable of structure.

Exercise 3
Write a program using structures that first inputs the data for 3 employees including their names,
emp-ids and salary. Apply bubble sort on the data entered and sort the employees on basis of
highly paid salary. Also apply linear search on this data to search the employee with his name
and display its further record on screen.

CS201: Data Structures and Algorithms Page 4

You might also like