University of Wah: Department of Computer Science
University of Wah: Department of Computer Science
2-D Arrays
Structure and pointers
1. 2-D Arrays
Task 1:
Write a program that first inputs rows and columns to apply the multiplication operation on two
matrices.
Output
2. Structures and Pointer
A structure is a user-defined data type in C/C++. A structure creates a data type that can
be used to group items of possibly different types into a single type.
The ‘struct’ keyword is used to create a structure. The general syntax to create a structure
is as shown below:
struct structureName{
member1;
member2;
member3;
.
.
.
memberN;
};
How to access the members of a structure?
Using objects of structure (dot (.) operator)
structureName s1;
s1.member2;
Using pointer variables (-> operator)
structureNAME *ptr= new structureName;
ptr -> member2;
Task1:
Write a program that take input values from the user swaps the values with the help of pointers.
Output
Task 2:
Write a program to initialize a void pointer, pass address of a float value to pointer and print the
address of float value and the pointer
Task 3:
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.
Output:
Task 4:
Modify above stated program by accessing structure using pointer type variable of structure.
Output
Task 5:
Write a program using structures that first inputs the data for 3 employees including their names,
emp-ids and salary. Apply linear search on this data to search the employee with his name and
display its further record on screen.