SlideShare a Scribd company logo
33
Set 3 Q1 Define a structure called cricket that will describe the following
information.
Player name, Team name, Batting Average
Using cricket declare an array player with n elements and write a program to read
the information about all the n elements and print a team-wise listing containing
names of players with their batting average
Program
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct cricket
{
char plyname[20];
char teamname[20];
float batavg;
};
int main()
{
struct cricket *player;
int i, no,j,k,nop;
char team[20][20], temp[20][20], temp1[20];
printf("Enter number of players ");
scanf("%d", &no);
nop=no;
player = (struct cricket*) malloc (no * sizeof(struct cricket));
34
for(i = 0; i < no; i++)
{
printf("Details of Player %dn",i+1);
fflush(stdin);
printf("Enter the Player Name : ");
gets((player+i)->plyname);
fflush(stdin);
printf("Enter the Team Name : ");
gets((player+i)->teamname);
fflush(stdin);
printf("Enter the Batting Average : ");
scanf("%f",&((player+i))->batavg);
}
for(i = 0; i < no; i++)
{
strcpy(team[i],(player+i)->teamname);
strcpy(temp[i],team[i]);
}
for (i = 0; i < no; i++)
{
for (j = i + 1; j < no;)
{
if (strcmp(temp[j],team[i])==0)
{
for (k = j; k < no; k++)
{
35
strcpy(temp[k], temp[k + 1]);
}
no--;
}
else
j++;
}
}
printf("n Player's Details:n");
printf("Country tt Name tt Batting Averagen");
for(i=0;i<j;i++)
{
printf("%sn",temp[i]);
strcpy(temp1,temp[i]);
for(k=0;k<nop;k++)
{
if(strcmp((player+k)->teamname,temp1)==0)
printf("ttt%sttt%.2fn",(player+k)->plyname,
(player+k)->batavg);
}
}
free (player);
return 0;
}
36
Output
Enter the Player Name : dhoni
Enter the Team Name : australia
Enter the Batting Average : 89
Details of Player 3
Enter the Player Name : ricky
Enter the Team Name : australia
Enter the Batting Average : 56
Details of Player 4
Enter the Player Name : ganguly
Enter the Team Name : india
Enter the Batting Average : 62
Details of Player 5
Enter the Player Name : sreesanth
Enter the Team Name : kenya
Enter the Batting Average : 82
Player's Details:
Country Name Batting Average
india
sachin 78.00
ganguly 62.00
australia
dhoni 89.00
ricky 56.00
kenya
sreesanth 82.00
37
Set 3 Q2 Define a structure that can describe a Hotel. It should have members
that include the name, address, grade, average room charge and number of rooms.
Write functions to perform the following operations:
a)To print out hotels of a given grade in order of charges.
b)To print out hotels with room charges less than a given value.
Program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct details
{
char name[40],address[40],grade;
float rate;
int num;
};
void search1(struct details *ob,char g,int n);
void search2(struct details *ob,float r,int n);
int main()
{
struct details *hotel;
int n,i;
char g;
38
float rate;
puts("Enter the number of hotels:");
scanf("%d",&n);
hotel = (struct details*) malloc (n * sizeof(struct details));
for(i=0;i<n;i++)
{
printf("Details of hotel %dn",i+1);
fflush(stdin);
printf("Enter the hotel name:");
gets((hotel+i)->name);
fflush(stdin);
printf("Enter the hotel address:");
gets((hotel+i)->address);
fflush(stdin);
printf("Enter the hotel grade:-('a','b','c','d')");
scanf("%c",&(hotel+i)->grade);
fflush(stdin);
puts("Enter the room charge:");
scanf("%f",&(hotel+i)->rate);
fflush(stdin);
puts("Enter the room numbers:");
scanf("%d",&(hotel+i)->num);
}
fflush(stdin);
39
printf("Search for specific hotelsn");
printf("Enter the grade for hotel('a','b','c','d'):");
scanf("%c",&g);
search1(hotel,g,n);
printf("nEnter the maximum charge:");
scanf("%f",&rate);
search2(hotel,rate,n);
return 0;
}
void search1(struct details *ob,char g,int n)
{
int i,j,x=0;
int flag=1;
char final[n][40],temp[40];
float r[n],t;
for(i=0;i<n;i++)
{
if(g==ob[i].grade)
{
strcpy(final[x],ob[i].name);
r[x]=ob[i].rate;
x++;
flag=0;
}
}
for(i=0;i<x;i++)
40
{
for(j=i+1;j<x;j++)
{
if(r[i]>r[j])
{
t=r[i];
r[i]=r[j];
r[j]=t;
strcpy(temp,final[i]);
strcpy(final[i],final[j]);
strcpy(final[j],temp);
}
}
}
if (flag==0)
{
printf("Hotel names with specified GRADE in order of charge");
for(i=0;i<x;i++)
{
printf("n%stt%.2f",final[i],r[i]);
}
}
else
printf("Hotel in the grade %c not available", g);
}
void search2(struct details *ob,float r1,int n)
41
{
int i,x=0;
int flag=1;
char final[n][40];
float r[n];
for(i=0;i<n;i++)
{
if(r1>ob[i].rate)
{
r[x]=ob[i].rate;
strcpy(final[x],ob[i].name);
x++;
flag=0;
}
}
if (flag==0)
{
printf("Hotel names below the specified RATE.");
for(i=0;i<x;i++)
{
printf("n%stt%.2f",final[i],r[i]);
}
}
else
printf("No hotel room below %0.2f available", r1);
}
42
Output
Enter the number of hotels:
5
Details of hotel 1
Enter the hotel name:rudra
Enter the hotel address:calicut
Enter the hotel grade:-('a','b','c','d')a
Enter the room charge:
250
Enter the room numbers:
10
Details of hotel 2
Enter the hotel name:agni
Enter the hotel address:kochi
Enter the hotel grade:-('a','b','c','d')a
Enter the room charge:
500
Enter the room numbers:
20
Details of hotel 3
Enter the hotel name:prithvi
Enter the hotel address:pathanamthitta
Enter the hotel grade:-('a','b','c','d')b
Enter the room charge:
1000
Enter the room numbers:
43
5
Details of hotel 4
Enter the hotel name:solo
Enter the hotel address:trivandrum
Enter the hotel grade:-('a','b','c','d')c
Enter the room charge:
100
Enter the room numbers:
30
Details of hotel 5
Enter the hotel name:sagar
Enter the hotel address:trivandrum
Enter the hotel grade:-('a','b','c','d')a
Enter the room charge:
500
Enter the room numbers:
5
Search for specific hotels
Enter the grade for hotel('a','b','c','d'):a
Hotel names with specified GRADE in order of charge
rudra 250.00
agni 500.00
sagar 500.00
Enter the maximum charge:300
Hotel names below the specified RATE.
rudra 250.00
solo 100.00
44
Set 3 Q3 Define a structure named mea_class which include the following
members:
Roll number, Name, mark of 5 subjects.
Write a program to calculate the aggregate percentage and the grade of each
student, and print the details in a neat format. The constraint for grading is as
follows:
Aggregate % Grade
>=95 A++
>=85 and <95 A+
>=80 and <85 A
>=75 and <80 B++
>=70 and <75 B+
>=60 and <70 B
>=50 and <60 C
<50 F
Program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct mca_class
{
int rollno;
char name[40];
int mark[5];
float per;
45
char grade[3];
};
void read (struct mca_class *student,int n);
void display(struct mca_class *student,int n);
int main()
{
struct mca_class *student;
int n;
puts("Enter the number of students");
scanf("%d",&n);
student = (struct mca_class*) malloc (n * sizeof(struct mca_class));
read (student,n);
display (student,n);
return 0 ;
}
void read (struct mca_class *student,int n)
{
int i,j;
float total,per;
char gr[3];
for(i=0;i<n;i++)
{
46
fflush(stdin);
printf("Student Roll No:");
scanf("%d",&(student+i)->rollno);
fflush(stdin);
printf("Enter the Student name:");
gets((student+i)->name);
fflush(stdin);
printf("Enter the mark of subjects out of 100 n");
total=0;
for (j=0;j<5;j++)
{
printf("Enter the mark of subject %d:",j+1);
scanf("%d",&(student+i)->mark[j]);
total=total+(student+i)->mark[j];
}
per=total/5;
student[i].per=per;
printf("%0.2f,",per);
if (per>=95)
strcpy(gr,"A++");
else if ((per>=85)&&(per<95))
strcpy(gr,"A+");
else if ((per>=80)&&(per<85))
strcpy(gr,"A");
else if ((per>=75)&&(per<80))
strcpy(gr,"B++");
else if ((per>=70)&&(per<75))
47
strcpy(gr,"B+");
else if ((per>=60)&&(per<70))
strcpy(gr,"B");
else if ((per>=50)&&(per<60))
strcpy(gr,"C");
else
strcpy(gr,"F");
strcpy((student+i)->grade,gr);
}
}
void display(struct mca_class *student,int n)
{
int i,j;
if(student == NULL)
{
printf("ERROR !!! NULL pointer !!!n");
return;
}
else
{
printf("List of students:n");
printf("=========================n");
printf("Roll NotNametMark 1tMark 2tMark 3tMark 4tMark
5tPertGraden");
48
printf("===============================================
==========================n");
for(i=0;i<n;i++)
{
printf("%dt%s",(student+i)->rollno,(student+i)-
>name);
for(j=0;j<5;j++)
{
printf("t%d",(student+i)->mark[j]);
}
printf("t%.2ft%sn",(student+i)->per,(student+i)-
>grade);
}
printf("n");
}
}
Output
Enter the number of students
5
Student Roll No:1
Enter the Student name:aakash
Enter the mark of subjects out of 100
Enter the mark of subject 1:80
Enter the mark of subject 2:45
Enter the mark of subject 3:35
Enter the mark of subject 4:14
49
Enter the mark of subject 5:78
Student Roll No:2
Enter the Student name:binu
Enter the mark of subjects out of 100
Enter the mark of subject 1:48
Enter the mark of subject 2:23
Enter the mark of subject 3:17
Enter the mark of subject 4:14
Enter the mark of subject 5:85
Student Roll No:3
Enter the Student name:eva
Enter the mark of subjects out of 100
Enter the mark of subject 1:12
Enter the mark of subject 2:10
Enter the mark of subject 3:09
Enter the mark of subject 4:7
Enter the mark of subject 5:05
Student Roll No:4
Enter the Student name:joshi
Enter the mark of subjects out of 100
Enter the mark of subject 1:45
Enter the mark of subject 2:99
Enter the mark of subject 3:98
Enter the mark of subject 4:96
Enter the mark of subject 5:93
Student Roll No:5
Enter the Student name:santhi
50
Enter the mark of subjects out of 100
Enter the mark of subject 1:78
Enter the mark of subject 2:99
Enter the mark of subject 3:91
Enter the mark of subject 4:85
Enter the mark of subject 5:23
List of students:
=========================
Roll No Name Mark 1 Mark 2 Mark 3 Mark 4 Mark 5 Per Grade
=========================================================
1 aakash 80 45 35 14 78 50.40 C
2 binu 48 23 17 14 85 37.40 F
3 eva 12 10 9 7 5 8.60 F
4 joshi 45 99 98 96 93 86.20 A+
5 santhi 78 99 91 85 23 75.20 B++
51
Set 3Q5 Define a structure named employee consisting of the following members:
Employee ID, Name, Department, Basic Salary, DA (in %), HRA(in%).
Write a program to prepare the pay-slip of the employees of a particular
department, using array of structures.
Program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct employee
{
int empid;
char name[40];
char dept[40];
float basic;
float da;
float hra;
float gross;
};
void read (struct employee *emp,int n);
void display(struct employee *emp,char* dept,int n);
int main()
{
52
struct employee *emp;
int n;
char dept[40];
puts("Enter the number of employees");
scanf("%d",&n);
emp = (struct employee*) malloc (n * sizeof(struct employee));
read (emp,n);
puts("Enter the dept name of employees whose pay slip is to be displayed:
n");
fflush(stdin);
gets(dept);;
display (emp,dept,n);
free(emp);
return 0 ;
}
void read (struct employee *emp,int n)
{
int i;
float da,hra;
printf("Enter da rate: ");
scanf("%f",&da);
53
printf("Enter hra rate: ");
scanf("%f",&hra);
for(i=0;i<n;i++)
{
printf("Enter employee ID: ");
scanf("%d",&(emp+i)->empid);
printf("Enter name of the employee: ");
fflush(stdin);
gets((emp+i)->name);
printf("Enter Department name: ");
fflush(stdin);
gets((emp+i)->dept);
printf("Enter Basic salary: n");
scanf("%f",&(emp+i)->basic);
(emp+i)->da = ((emp+i)->basic*da)/100;
(emp+i)->hra = ((emp+i)->basic*hra)/100;
(emp+i)->gross = (emp+i)->basic + (emp+i)->da + (emp+i)->hra;
}
}
void display(struct employee *emp,char* dept,int n)
{
int i,found =0;
54
if(emp == NULL)
{
printf("ERROR !!! NULL pointer !!!n");
return;
}
else
{
printf("nPay-slip of employees of department : %sn",dept);
printf("n");
printf("Emp IDtNametBasictDAtHRAtGross Salaryn");
printf("===============================================
===========n");
for(i=0;i<n;i++)
{
if(strcmp((emp+i)->dept,dept)==0)
{
printf("%dt%st%.2ft%.2ft%.2ft%.2fn",(emp+i)-
>empid,(emp+i)->name,(emp+i)->basic,(emp+i)->da,(emp+i)->hra,(emp+i)-
>gross);
found =1;
}
}
if(found ==0)
printf("nPay-slips NOT FOUND for the requested Dept-
%s!!!!!!!!n",dept);
printf("n");
}
55
}
Output
Enter the number of employees
5
Enter da rate: 5
Enter hra rate: 10
Enter employee ID: 1
Enter name of the employee: sarun
Enter Department name: it
Enter Basic salary:
1000
Enter employee ID: 2
Enter name of the employee: sajan
Enter Department name: sales
Enter Basic salary:
2000
Enter employee ID: 3
Enter name of the employee: joby
Enter Department name: it
Enter Basic salary:
5000
Enter employee ID: 4
Enter name of the employee: ginu
Enter Department name: it
Enter Basic salary:
2000
56
Enter employee ID: 5
Enter name of the employee: shibu
Enter Department name: marketing
Enter Basic salary:
5400
Enter the dept name of employees whose pay slip is to be displayed:
it
Pay-slip of employees of department : it
Emp ID Name Basic DA HRA Gross Salary
=========================================================
1 sarun 1000.00 50.00 100.00 1150.00
3 joby 5000.00 250.00 500.00 5750.00
4 ginu 2000.00 100.00 200.00 2300.00
57
Set 3 Q5Write a program to accept records of the different states using array of
structures. The structure should contain state_name, population, literacy_rate and
per_capita_income. Assume suitable data. Display the state whose literacy rate is
highest and whose per capita income is highest. (use typedef in the program).
Program
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef struct statedemography
{
char state_name[50];
long int population;
float literacy_rate;
float per_capita_income;
}statedetails;
void readstate(statedetails * , int );
void printstate(statedetails * , int);
int main(void)
{
int n;
statedetails *state;
58
printf("Enter the number of states: ");
scanf("%d", &n);
state = (statedetails*)malloc(sizeof(statedetails)*n);
readstate(state, n);
printstate(state, n);
free(state);
return 0;
}
void readstate(statedetails *state, int n)
{
int i;
for(i=0;i<n;i++)
{
printf("Enter name of the state: n");
fflush(stdin);
gets((state+i)->state_name);
printf("nEnter population: n");
scanf("%ld",&(state+i)->population);
printf("Enter literacy rate: n");
scanf("%f",&(state+i)->literacy_rate);
printf("Enter per capita income: n");
59
scanf("%f",&(state+i)->per_capita_income);
}
}
void printstate(statedetails *state, int n)
{
int i;
if(state == NULL)
{
printf("ERROR !!! NULL pointer !!!n");
return;
}
else
{
float maxLiteracy, maxpercapIncome;
i=0;
maxLiteracy = (state+i)->literacy_rate;
maxpercapIncome = (state+i)->per_capita_income;
for(i=1;i<n;i++)
{
if ((state+i)->literacy_rate > maxLiteracy)
maxLiteracy = (state+i)->literacy_rate;
if ((state+i)->per_capita_income > maxpercapIncome)
60
maxpercapIncome = (state+i)->per_capita_income;
}
for(i=0;i<n;i++)
{
if ((state+i)->literacy_rate == maxLiteracy)
printf("State %s",(state+i)->state_name);
printf(" have Maximum literacy
rate:%.2fn",maxLiteracy);
}
printf("n");
for(i=0;i<n;i++)
{
if ((state+i)->per_capita_income == maxpercapIncome)
printf("State %s ",(state+i)->state_name);
printf(" have Maximum per capita
income:%.2fn",maxpercapIncome);
}
printf("n");
}
}
61
Output
Enter the number of states: 5
Enter name of the state: kerala
Enter population: 15000
Enter literacy rate: 99
Enter per capita income: 5000
Enter name of the state: bihar
Enter population: 58000
Enter literacy rate: 85
Enter per capita income: 1500
Enter name of the state: gujarat
Enter population: 90000
Enter literacy rate: 45
Enter per capita income: 7400
Enter name of the state: punjab
Enter population: 56000
Enter literacy rate: 23
Enter per capita income: 4800
Enter name of the state: goa
Enter population: 96000
Enter literacy rate: 93
Enter per capita income: 5200
State kerala have Maximum literacy rate:99.00
State gujarat have Maximum per capita income:7400.00

More Related Content

What's hot (20)

PPT
Introduction to Basic C programming 01
Wingston
 
PPTX
Color Image Processing
kiruthiammu
 
PPTX
Character Attribute in computer graphics
HariTharshiniBscIT1
 
PPTX
Lecture 21 problem reduction search ao star search
Hema Kashyap
 
PPT
Polygon Fill
wahab13
 
PPTX
Computer animation
Karan Singh Rawat
 
PPTX
Chapter 3 Output Primitives
PrathimaBaliga
 
PPTX
Bezier curve computer graphics
University of Potsdam
 
PPT
Jpeg and mpeg ppt
siddharth rathore
 
PPTX
Rendering Algorithms.pptx
SherinRappai
 
PPTX
YIQ by R.Chinthamani.pptx
SindhuVelmukull
 
PPTX
KEY FRAME SYSTEM-Ruby Stella mary.pptx
ComputerScienceDepar6
 
PDF
Numeric Data types in Python
jyostna bodapati
 
PPTX
computer animation languages-N.Kavitha.pptx
ComputerScienceDepar6
 
PPTX
Raster animation
abhijit754
 
PPT
Vector graphics
lenance
 
PPTX
Image forgery and security
أحلام انصارى
 
PPTX
Computer graphics basic transformation
Selvakumar Gna
 
PPTX
Computer Graphics
Deepak Kumar Mohapatra
 
PPTX
Python programming: Anonymous functions, String operations
Megha V
 
Introduction to Basic C programming 01
Wingston
 
Color Image Processing
kiruthiammu
 
Character Attribute in computer graphics
HariTharshiniBscIT1
 
Lecture 21 problem reduction search ao star search
Hema Kashyap
 
Polygon Fill
wahab13
 
Computer animation
Karan Singh Rawat
 
Chapter 3 Output Primitives
PrathimaBaliga
 
Bezier curve computer graphics
University of Potsdam
 
Jpeg and mpeg ppt
siddharth rathore
 
Rendering Algorithms.pptx
SherinRappai
 
YIQ by R.Chinthamani.pptx
SindhuVelmukull
 
KEY FRAME SYSTEM-Ruby Stella mary.pptx
ComputerScienceDepar6
 
Numeric Data types in Python
jyostna bodapati
 
computer animation languages-N.Kavitha.pptx
ComputerScienceDepar6
 
Raster animation
abhijit754
 
Vector graphics
lenance
 
Image forgery and security
أحلام انصارى
 
Computer graphics basic transformation
Selvakumar Gna
 
Computer Graphics
Deepak Kumar Mohapatra
 
Python programming: Anonymous functions, String operations
Megha V
 

Similar to C programs Set 3 (20)

PDF
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
PDF
Zoro123456789123456789123456789123456789
Ghh
 
PDF
labb123456789123456789123456789123456789
Ghh
 
PDF
C- Programming Assignment 3
Animesh Chaturvedi
 
PPTX
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
AntareepMajumder
 
PPTX
C language
Priya698357
 
PDF
DSC program.pdf
Prof. Dr. K. Adisesha
 
PDF
C faq pdf
DebiPanda
 
DOCX
Cs pritical file
Mitul Patel
 
PDF
C language concept with code apna college.pdf
mhande899
 
PPTX
งานนำเสนอ1
Mook Prapasson
 
PDF
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
PPS
pointers 1
gaurav koriya
 
DOC
Useful c programs
MD SHAH FAHAD
 
DOCX
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Sonu62614
 
PDF
structure1.pdf
AbhimanyuKumarYadav3
 
PDF
Principals of Programming in CModule -5.pdfModule-3.pdf
anilcsbs
 
PDF
C Programming Lab.pdf
MOJO89
 
PPT
Unit 3 arrays and_string
kirthika jeyenth
 
PPT
Arrays in c
vampugani
 
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
Zoro123456789123456789123456789123456789
Ghh
 
labb123456789123456789123456789123456789
Ghh
 
C- Programming Assignment 3
Animesh Chaturvedi
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
AntareepMajumder
 
C language
Priya698357
 
DSC program.pdf
Prof. Dr. K. Adisesha
 
C faq pdf
DebiPanda
 
Cs pritical file
Mitul Patel
 
C language concept with code apna college.pdf
mhande899
 
งานนำเสนอ1
Mook Prapasson
 
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
pointers 1
gaurav koriya
 
Useful c programs
MD SHAH FAHAD
 
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Sonu62614
 
structure1.pdf
AbhimanyuKumarYadav3
 
Principals of Programming in CModule -5.pdfModule-3.pdf
anilcsbs
 
C Programming Lab.pdf
MOJO89
 
Unit 3 arrays and_string
kirthika jeyenth
 
Arrays in c
vampugani
 
Ad

More from Koshy Geoji (9)

PDF
Computer Graphics Report
Koshy Geoji
 
PDF
C programs Set 4
Koshy Geoji
 
PDF
C programs Set 2
Koshy Geoji
 
PDF
C programs
Koshy Geoji
 
PPTX
Vehicle detection in Aerial Images
Koshy Geoji
 
PPTX
Text mining
Koshy Geoji
 
PPTX
Hypothesis test based approach for change detection
Koshy Geoji
 
DOCX
Seminar report
Koshy Geoji
 
DOCX
73347633 milma-os
Koshy Geoji
 
Computer Graphics Report
Koshy Geoji
 
C programs Set 4
Koshy Geoji
 
C programs Set 2
Koshy Geoji
 
C programs
Koshy Geoji
 
Vehicle detection in Aerial Images
Koshy Geoji
 
Text mining
Koshy Geoji
 
Hypothesis test based approach for change detection
Koshy Geoji
 
Seminar report
Koshy Geoji
 
73347633 milma-os
Koshy Geoji
 
Ad

Recently uploaded (20)

PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPTX
How to Consolidate Subscription Billing in Odoo 18 Sales
Celine George
 
PPTX
Presentation: Climate Citizenship Digital Education
Karl Donert
 
PPTX
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
PDF
A guide to responding to Section C essay tasks for the VCE English Language E...
jpinnuck
 
PPTX
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PDF
Living Systems Unveiled: Simplified Life Processes for Exam Success
omaiyairshad
 
PPTX
PYLORIC STENOSIS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Various Psychological tests: challenges and contemporary trends in psychologi...
santoshmohalik1
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PPTX
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
PDF
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
PPTX
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
PDF
FULL DOCUMENT: Read the full Deloitte and Touche audit report on the National...
Kweku Zurek
 
PDF
Right to Information.pdf by Sapna Maurya XI D
Directorate of Education Delhi
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
How to Consolidate Subscription Billing in Odoo 18 Sales
Celine George
 
Presentation: Climate Citizenship Digital Education
Karl Donert
 
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
A guide to responding to Section C essay tasks for the VCE English Language E...
jpinnuck
 
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Living Systems Unveiled: Simplified Life Processes for Exam Success
omaiyairshad
 
PYLORIC STENOSIS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Various Psychological tests: challenges and contemporary trends in psychologi...
santoshmohalik1
 
digestive system for Pharm d I year HAP
rekhapositivity
 
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
FULL DOCUMENT: Read the full Deloitte and Touche audit report on the National...
Kweku Zurek
 
Right to Information.pdf by Sapna Maurya XI D
Directorate of Education Delhi
 

C programs Set 3

  • 1. 33 Set 3 Q1 Define a structure called cricket that will describe the following information. Player name, Team name, Batting Average Using cricket declare an array player with n elements and write a program to read the information about all the n elements and print a team-wise listing containing names of players with their batting average Program #include <string.h> #include <stdio.h> #include <stdlib.h> struct cricket { char plyname[20]; char teamname[20]; float batavg; }; int main() { struct cricket *player; int i, no,j,k,nop; char team[20][20], temp[20][20], temp1[20]; printf("Enter number of players "); scanf("%d", &no); nop=no; player = (struct cricket*) malloc (no * sizeof(struct cricket));
  • 2. 34 for(i = 0; i < no; i++) { printf("Details of Player %dn",i+1); fflush(stdin); printf("Enter the Player Name : "); gets((player+i)->plyname); fflush(stdin); printf("Enter the Team Name : "); gets((player+i)->teamname); fflush(stdin); printf("Enter the Batting Average : "); scanf("%f",&((player+i))->batavg); } for(i = 0; i < no; i++) { strcpy(team[i],(player+i)->teamname); strcpy(temp[i],team[i]); } for (i = 0; i < no; i++) { for (j = i + 1; j < no;) { if (strcmp(temp[j],team[i])==0) { for (k = j; k < no; k++) {
  • 3. 35 strcpy(temp[k], temp[k + 1]); } no--; } else j++; } } printf("n Player's Details:n"); printf("Country tt Name tt Batting Averagen"); for(i=0;i<j;i++) { printf("%sn",temp[i]); strcpy(temp1,temp[i]); for(k=0;k<nop;k++) { if(strcmp((player+k)->teamname,temp1)==0) printf("ttt%sttt%.2fn",(player+k)->plyname, (player+k)->batavg); } } free (player); return 0; }
  • 4. 36 Output Enter the Player Name : dhoni Enter the Team Name : australia Enter the Batting Average : 89 Details of Player 3 Enter the Player Name : ricky Enter the Team Name : australia Enter the Batting Average : 56 Details of Player 4 Enter the Player Name : ganguly Enter the Team Name : india Enter the Batting Average : 62 Details of Player 5 Enter the Player Name : sreesanth Enter the Team Name : kenya Enter the Batting Average : 82 Player's Details: Country Name Batting Average india sachin 78.00 ganguly 62.00 australia dhoni 89.00 ricky 56.00 kenya sreesanth 82.00
  • 5. 37 Set 3 Q2 Define a structure that can describe a Hotel. It should have members that include the name, address, grade, average room charge and number of rooms. Write functions to perform the following operations: a)To print out hotels of a given grade in order of charges. b)To print out hotels with room charges less than a given value. Program #include <stdlib.h> #include <stdio.h> #include <string.h> struct details { char name[40],address[40],grade; float rate; int num; }; void search1(struct details *ob,char g,int n); void search2(struct details *ob,float r,int n); int main() { struct details *hotel; int n,i; char g;
  • 6. 38 float rate; puts("Enter the number of hotels:"); scanf("%d",&n); hotel = (struct details*) malloc (n * sizeof(struct details)); for(i=0;i<n;i++) { printf("Details of hotel %dn",i+1); fflush(stdin); printf("Enter the hotel name:"); gets((hotel+i)->name); fflush(stdin); printf("Enter the hotel address:"); gets((hotel+i)->address); fflush(stdin); printf("Enter the hotel grade:-('a','b','c','d')"); scanf("%c",&(hotel+i)->grade); fflush(stdin); puts("Enter the room charge:"); scanf("%f",&(hotel+i)->rate); fflush(stdin); puts("Enter the room numbers:"); scanf("%d",&(hotel+i)->num); } fflush(stdin);
  • 7. 39 printf("Search for specific hotelsn"); printf("Enter the grade for hotel('a','b','c','d'):"); scanf("%c",&g); search1(hotel,g,n); printf("nEnter the maximum charge:"); scanf("%f",&rate); search2(hotel,rate,n); return 0; } void search1(struct details *ob,char g,int n) { int i,j,x=0; int flag=1; char final[n][40],temp[40]; float r[n],t; for(i=0;i<n;i++) { if(g==ob[i].grade) { strcpy(final[x],ob[i].name); r[x]=ob[i].rate; x++; flag=0; } } for(i=0;i<x;i++)
  • 8. 40 { for(j=i+1;j<x;j++) { if(r[i]>r[j]) { t=r[i]; r[i]=r[j]; r[j]=t; strcpy(temp,final[i]); strcpy(final[i],final[j]); strcpy(final[j],temp); } } } if (flag==0) { printf("Hotel names with specified GRADE in order of charge"); for(i=0;i<x;i++) { printf("n%stt%.2f",final[i],r[i]); } } else printf("Hotel in the grade %c not available", g); } void search2(struct details *ob,float r1,int n)
  • 9. 41 { int i,x=0; int flag=1; char final[n][40]; float r[n]; for(i=0;i<n;i++) { if(r1>ob[i].rate) { r[x]=ob[i].rate; strcpy(final[x],ob[i].name); x++; flag=0; } } if (flag==0) { printf("Hotel names below the specified RATE."); for(i=0;i<x;i++) { printf("n%stt%.2f",final[i],r[i]); } } else printf("No hotel room below %0.2f available", r1); }
  • 10. 42 Output Enter the number of hotels: 5 Details of hotel 1 Enter the hotel name:rudra Enter the hotel address:calicut Enter the hotel grade:-('a','b','c','d')a Enter the room charge: 250 Enter the room numbers: 10 Details of hotel 2 Enter the hotel name:agni Enter the hotel address:kochi Enter the hotel grade:-('a','b','c','d')a Enter the room charge: 500 Enter the room numbers: 20 Details of hotel 3 Enter the hotel name:prithvi Enter the hotel address:pathanamthitta Enter the hotel grade:-('a','b','c','d')b Enter the room charge: 1000 Enter the room numbers:
  • 11. 43 5 Details of hotel 4 Enter the hotel name:solo Enter the hotel address:trivandrum Enter the hotel grade:-('a','b','c','d')c Enter the room charge: 100 Enter the room numbers: 30 Details of hotel 5 Enter the hotel name:sagar Enter the hotel address:trivandrum Enter the hotel grade:-('a','b','c','d')a Enter the room charge: 500 Enter the room numbers: 5 Search for specific hotels Enter the grade for hotel('a','b','c','d'):a Hotel names with specified GRADE in order of charge rudra 250.00 agni 500.00 sagar 500.00 Enter the maximum charge:300 Hotel names below the specified RATE. rudra 250.00 solo 100.00
  • 12. 44 Set 3 Q3 Define a structure named mea_class which include the following members: Roll number, Name, mark of 5 subjects. Write a program to calculate the aggregate percentage and the grade of each student, and print the details in a neat format. The constraint for grading is as follows: Aggregate % Grade >=95 A++ >=85 and <95 A+ >=80 and <85 A >=75 and <80 B++ >=70 and <75 B+ >=60 and <70 B >=50 and <60 C <50 F Program #include <stdlib.h> #include <stdio.h> #include <string.h> struct mca_class { int rollno; char name[40]; int mark[5]; float per;
  • 13. 45 char grade[3]; }; void read (struct mca_class *student,int n); void display(struct mca_class *student,int n); int main() { struct mca_class *student; int n; puts("Enter the number of students"); scanf("%d",&n); student = (struct mca_class*) malloc (n * sizeof(struct mca_class)); read (student,n); display (student,n); return 0 ; } void read (struct mca_class *student,int n) { int i,j; float total,per; char gr[3]; for(i=0;i<n;i++) {
  • 14. 46 fflush(stdin); printf("Student Roll No:"); scanf("%d",&(student+i)->rollno); fflush(stdin); printf("Enter the Student name:"); gets((student+i)->name); fflush(stdin); printf("Enter the mark of subjects out of 100 n"); total=0; for (j=0;j<5;j++) { printf("Enter the mark of subject %d:",j+1); scanf("%d",&(student+i)->mark[j]); total=total+(student+i)->mark[j]; } per=total/5; student[i].per=per; printf("%0.2f,",per); if (per>=95) strcpy(gr,"A++"); else if ((per>=85)&&(per<95)) strcpy(gr,"A+"); else if ((per>=80)&&(per<85)) strcpy(gr,"A"); else if ((per>=75)&&(per<80)) strcpy(gr,"B++"); else if ((per>=70)&&(per<75))
  • 15. 47 strcpy(gr,"B+"); else if ((per>=60)&&(per<70)) strcpy(gr,"B"); else if ((per>=50)&&(per<60)) strcpy(gr,"C"); else strcpy(gr,"F"); strcpy((student+i)->grade,gr); } } void display(struct mca_class *student,int n) { int i,j; if(student == NULL) { printf("ERROR !!! NULL pointer !!!n"); return; } else { printf("List of students:n"); printf("=========================n"); printf("Roll NotNametMark 1tMark 2tMark 3tMark 4tMark 5tPertGraden");
  • 16. 48 printf("=============================================== ==========================n"); for(i=0;i<n;i++) { printf("%dt%s",(student+i)->rollno,(student+i)- >name); for(j=0;j<5;j++) { printf("t%d",(student+i)->mark[j]); } printf("t%.2ft%sn",(student+i)->per,(student+i)- >grade); } printf("n"); } } Output Enter the number of students 5 Student Roll No:1 Enter the Student name:aakash Enter the mark of subjects out of 100 Enter the mark of subject 1:80 Enter the mark of subject 2:45 Enter the mark of subject 3:35 Enter the mark of subject 4:14
  • 17. 49 Enter the mark of subject 5:78 Student Roll No:2 Enter the Student name:binu Enter the mark of subjects out of 100 Enter the mark of subject 1:48 Enter the mark of subject 2:23 Enter the mark of subject 3:17 Enter the mark of subject 4:14 Enter the mark of subject 5:85 Student Roll No:3 Enter the Student name:eva Enter the mark of subjects out of 100 Enter the mark of subject 1:12 Enter the mark of subject 2:10 Enter the mark of subject 3:09 Enter the mark of subject 4:7 Enter the mark of subject 5:05 Student Roll No:4 Enter the Student name:joshi Enter the mark of subjects out of 100 Enter the mark of subject 1:45 Enter the mark of subject 2:99 Enter the mark of subject 3:98 Enter the mark of subject 4:96 Enter the mark of subject 5:93 Student Roll No:5 Enter the Student name:santhi
  • 18. 50 Enter the mark of subjects out of 100 Enter the mark of subject 1:78 Enter the mark of subject 2:99 Enter the mark of subject 3:91 Enter the mark of subject 4:85 Enter the mark of subject 5:23 List of students: ========================= Roll No Name Mark 1 Mark 2 Mark 3 Mark 4 Mark 5 Per Grade ========================================================= 1 aakash 80 45 35 14 78 50.40 C 2 binu 48 23 17 14 85 37.40 F 3 eva 12 10 9 7 5 8.60 F 4 joshi 45 99 98 96 93 86.20 A+ 5 santhi 78 99 91 85 23 75.20 B++
  • 19. 51 Set 3Q5 Define a structure named employee consisting of the following members: Employee ID, Name, Department, Basic Salary, DA (in %), HRA(in%). Write a program to prepare the pay-slip of the employees of a particular department, using array of structures. Program #include <stdlib.h> #include <stdio.h> #include <string.h> struct employee { int empid; char name[40]; char dept[40]; float basic; float da; float hra; float gross; }; void read (struct employee *emp,int n); void display(struct employee *emp,char* dept,int n); int main() {
  • 20. 52 struct employee *emp; int n; char dept[40]; puts("Enter the number of employees"); scanf("%d",&n); emp = (struct employee*) malloc (n * sizeof(struct employee)); read (emp,n); puts("Enter the dept name of employees whose pay slip is to be displayed: n"); fflush(stdin); gets(dept);; display (emp,dept,n); free(emp); return 0 ; } void read (struct employee *emp,int n) { int i; float da,hra; printf("Enter da rate: "); scanf("%f",&da);
  • 21. 53 printf("Enter hra rate: "); scanf("%f",&hra); for(i=0;i<n;i++) { printf("Enter employee ID: "); scanf("%d",&(emp+i)->empid); printf("Enter name of the employee: "); fflush(stdin); gets((emp+i)->name); printf("Enter Department name: "); fflush(stdin); gets((emp+i)->dept); printf("Enter Basic salary: n"); scanf("%f",&(emp+i)->basic); (emp+i)->da = ((emp+i)->basic*da)/100; (emp+i)->hra = ((emp+i)->basic*hra)/100; (emp+i)->gross = (emp+i)->basic + (emp+i)->da + (emp+i)->hra; } } void display(struct employee *emp,char* dept,int n) { int i,found =0;
  • 22. 54 if(emp == NULL) { printf("ERROR !!! NULL pointer !!!n"); return; } else { printf("nPay-slip of employees of department : %sn",dept); printf("n"); printf("Emp IDtNametBasictDAtHRAtGross Salaryn"); printf("=============================================== ===========n"); for(i=0;i<n;i++) { if(strcmp((emp+i)->dept,dept)==0) { printf("%dt%st%.2ft%.2ft%.2ft%.2fn",(emp+i)- >empid,(emp+i)->name,(emp+i)->basic,(emp+i)->da,(emp+i)->hra,(emp+i)- >gross); found =1; } } if(found ==0) printf("nPay-slips NOT FOUND for the requested Dept- %s!!!!!!!!n",dept); printf("n"); }
  • 23. 55 } Output Enter the number of employees 5 Enter da rate: 5 Enter hra rate: 10 Enter employee ID: 1 Enter name of the employee: sarun Enter Department name: it Enter Basic salary: 1000 Enter employee ID: 2 Enter name of the employee: sajan Enter Department name: sales Enter Basic salary: 2000 Enter employee ID: 3 Enter name of the employee: joby Enter Department name: it Enter Basic salary: 5000 Enter employee ID: 4 Enter name of the employee: ginu Enter Department name: it Enter Basic salary: 2000
  • 24. 56 Enter employee ID: 5 Enter name of the employee: shibu Enter Department name: marketing Enter Basic salary: 5400 Enter the dept name of employees whose pay slip is to be displayed: it Pay-slip of employees of department : it Emp ID Name Basic DA HRA Gross Salary ========================================================= 1 sarun 1000.00 50.00 100.00 1150.00 3 joby 5000.00 250.00 500.00 5750.00 4 ginu 2000.00 100.00 200.00 2300.00
  • 25. 57 Set 3 Q5Write a program to accept records of the different states using array of structures. The structure should contain state_name, population, literacy_rate and per_capita_income. Assume suitable data. Display the state whose literacy rate is highest and whose per capita income is highest. (use typedef in the program). Program #include <stdlib.h> #include <string.h> #include <stdio.h> typedef struct statedemography { char state_name[50]; long int population; float literacy_rate; float per_capita_income; }statedetails; void readstate(statedetails * , int ); void printstate(statedetails * , int); int main(void) { int n; statedetails *state;
  • 26. 58 printf("Enter the number of states: "); scanf("%d", &n); state = (statedetails*)malloc(sizeof(statedetails)*n); readstate(state, n); printstate(state, n); free(state); return 0; } void readstate(statedetails *state, int n) { int i; for(i=0;i<n;i++) { printf("Enter name of the state: n"); fflush(stdin); gets((state+i)->state_name); printf("nEnter population: n"); scanf("%ld",&(state+i)->population); printf("Enter literacy rate: n"); scanf("%f",&(state+i)->literacy_rate); printf("Enter per capita income: n");
  • 27. 59 scanf("%f",&(state+i)->per_capita_income); } } void printstate(statedetails *state, int n) { int i; if(state == NULL) { printf("ERROR !!! NULL pointer !!!n"); return; } else { float maxLiteracy, maxpercapIncome; i=0; maxLiteracy = (state+i)->literacy_rate; maxpercapIncome = (state+i)->per_capita_income; for(i=1;i<n;i++) { if ((state+i)->literacy_rate > maxLiteracy) maxLiteracy = (state+i)->literacy_rate; if ((state+i)->per_capita_income > maxpercapIncome)
  • 28. 60 maxpercapIncome = (state+i)->per_capita_income; } for(i=0;i<n;i++) { if ((state+i)->literacy_rate == maxLiteracy) printf("State %s",(state+i)->state_name); printf(" have Maximum literacy rate:%.2fn",maxLiteracy); } printf("n"); for(i=0;i<n;i++) { if ((state+i)->per_capita_income == maxpercapIncome) printf("State %s ",(state+i)->state_name); printf(" have Maximum per capita income:%.2fn",maxpercapIncome); } printf("n"); } }
  • 29. 61 Output Enter the number of states: 5 Enter name of the state: kerala Enter population: 15000 Enter literacy rate: 99 Enter per capita income: 5000 Enter name of the state: bihar Enter population: 58000 Enter literacy rate: 85 Enter per capita income: 1500 Enter name of the state: gujarat Enter population: 90000 Enter literacy rate: 45 Enter per capita income: 7400 Enter name of the state: punjab Enter population: 56000 Enter literacy rate: 23 Enter per capita income: 4800 Enter name of the state: goa Enter population: 96000 Enter literacy rate: 93 Enter per capita income: 5200 State kerala have Maximum literacy rate:99.00 State gujarat have Maximum per capita income:7400.00