Beruflich Dokumente
Kultur Dokumente
Objectives:
To enhance programming skills using structures, array of structures and nested structures.
To understand the concept of unions and distinguish between structures & unions.
Sample Program:
main( )
int i;
struct employee
int id_no;
char sex;
};
for(i=0;i<=2;i++)
}
}
Modifications:
1. Make provisions for reading the data input from the user.
2. Write a function and use the same function for reading and printing the data by passing
structure.
Exercises:
1. Define a structure called cricket that will describe the following information:
Using cricket, declare an array players with 50 elements and write a program to read the
information about all the 50 players. Also print a team wise list containing names of players
with their batting averages.
2. Model a bookshop inventory program to maintain the inventory of books. The list includes
details such as author, title, price, publisher, stock position etc. Whenever the customer
wants a book, the shopkeeper inputs the title and the author name of the book and the
system replies whether it is in the list or not.
If it is in the list, then the system displays the book details and asks for the number of
copies. If the requested copies are available, the total cost of the books is displayed. Use
the concept of passing structures to functions. For publication date use the concept of
nested structures.
3. Define the structure for railway ticket and create an array of 10 tickets. Write a program
To store the ticket information to access the details of ticket i.e. train name, departure
time, date, list of passengers and ticket number.
Given a ticket number the status of the ticket is printed. i.e. waiting, confirm ,etc .if
confirm print passenger list with ticket number.
Lab – 2
Introduction to Pointers
Objective:
Sample Program:
main( )
{
int *p,*q;
int x,y,a;
x = 20; y =10;
p = &x;
q = &y;
a = *p + *q;
printf("value of a = %d\n",a);
}
Modification:
1. Modify the above program to calculate arithmetic operations using pointers and also read
input values from keyboard.
Exercise:
1. Write a program to convert decimal number entered by used in its equivalent binary number
using pointer.