Professional Documents
Culture Documents
FA20-BEE-2C-146 ICP Lab 12
FA20-BEE-2C-146 ICP Lab 12
Lab 12:
Structures
In-Lab task:
4.1. If we have the structure of the student given as and suppose we have ten students struct student
{
char name[20];
int eng;
int math;
int phys;
double mean;
};
a) We want to calculate mean of three subjects of each person.
b) We want to determine grade based on mean of three subjects and table shown in below. Confirm by
executing it.
Mean Grade
90 <= x <= 100 S
80 <= x < 90 A
70 <= x < 80 B
60 <= x < 70 C
x < 60 D
Answer:
#include <stdio.h>
struct Marks {
float eng_marks, maths_marks, phy_marks;
};
int main()
{
struct date
{
int day;
int month;
int year;
};
void main()
{
struct date d1,d2;
if((d1.day==d2.day)&&(d1.month==d2.month)&&(d1.year==d2.year))
printf("The dates are equal\n");
else
printf("The dates are unequal\n");
4.3. A record contains name of a footballer, his age, number of games he has played, and the average number of
goals has scored in each match. Create an array of structure to hold records of 20 such players and then write a
program to read these records. Program would be able to tell the name of player that has played maximum
number of matches, the name of youngest player and a player name who scored is lowest.
Answer:
#include<stdio.h>
struct cricketer
int avegoals;
int gamesplayed;
char name[25];
}player[100];
void main()
int i,n;
scanf("%d",&n);
printf("Enter player Name , Number of games played and Average goals in played games\n");
for(i=0;i<n;i++)
scanf("%s %d %d",player[i].name,&player[i].gamesplayed,&player[i].avegoals);
for(i=0;i<n;i++)
}
4.4. There is a structure called employee that holds information like employee code, name, date of joining.
Write a program to create an array of the structure and enter some data into it. Then ask the user to enter current
date. Display the names of those employees whose tenure is 3 or more than 3 years according to the given
current date.
Answer:
#include<stdio.h>
struct employee
{
int dd,mm,yy;
char code[10],name[10];
}emp[10];
int main()
{
int n,i,dd,mm,yy;
printf("Enter Numbers of Employees : ");
scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("\nEnter Emp Code : ");
scanf("%s",emp[i].code);
printf("Enter Emp Name : ");
scanf("%s",emp[i].name);
printf("Enter Join Date (dd mm yyyy) : ");
scanf("%d%d%d",&emp[i].dd,&emp[i].mm,&emp[i].yy);
}
printf("\nEnter current Date : ");
scanf("%d%d%d",&dd,&mm,&yy);
printf("Employees working for more than 3 years \n");
for(i=0;i<n;++i)
if((yy - emp[i].yy) >= 3)
printf("\nCode : %s Name : %s Date of Join : %d/%d/%d",
emp[i].code,emp[i].name, emp[i].dd,emp[i].mm,emp[i].yy);
return 0;
}
Home tasks
5.1. Write a menu driven program that depicts the working of a library. The menu options should be:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of specified book
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Create a structure called library to hold accession number, title of the book, author name, price of the book, and
flag indicating whether book is issued or not.