Upload
azharjaved
View
224
Download
0
Embed Size (px)
Citation preview
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 1/32
Chap10[D]a Printing specfic datas in structures
Create a structure to specify data on students given below: Roll number, Name,
Department, Course, Year of joining Assume that there are not more than !"
students in the collage# $a% &rite a function to print names of all students who
joined in a particular year# $b% &rite a function to print the data of a studentwhose roll number is given#
void main()
{
char j[1];
int yearc,rollc,i;
struct book
{int roll;
char name[20];
char department[20];
char course[20];
int year;
;
struct book b[!]"{
{1,#$r%#,#&cience#,#'hysics#,200,
{2,#$r#,#&cience#,#$aths#,200*,
{+,#$r#,#%rts#,#-istory#,200,
{.,#$rs/#,#%rts#,#-istory#,2010,
{!,#$rs#,#&cience#,#$aths#,200
;
hile(1)
{
clrscr();
print(#3nnter a year(2000 or 2001)3n#);
scan(#4d#,5yearc);or(i"0;i6!;i77)
{
i(yearc""b[i]8year)
print(#3n9ame: 4s ear: 4d#,b[i]8name,b[i]8year);
print(#3nnter a roll number(1<!)3n#);
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 2/32
scan(#4d#,5rollc);
or(i"0;i6!;i77)
{
i(rollc""b[i]8roll)
{print(#3n=oll number: 4d, 9ame: 4s, /epartment: 4s3nourse: 4s,ear:
4d#,b[i]8roll,b[i]8name,b[i]8department,b[i]8course,b[i]8year);
break;
print(#3n'ress > to >uit or any key to continue3n#);
scan(#4s#,j);
i(j[0]""11+)break;
linkloat()
{
loat a"0,?b;
b"5a;
a"?b;
Chap10[D]c Automobile has weird serial numbers
An automobile company has serial number for engine parts starting from AA" to
''(# )he other characteristics of parts to be specified in a structure are: Year of
manufacture, material and *uantity manufactured#
$a% +pecify a structure to store information corresponding to a part#
$b% &rite a program to retrieve information on parts with serial numbers between
- and CC.#
???@hen keyinA in the parts key alphabets in uppercase8
void main()
{
int i,j,letter,a,b,c,d;
char m[+],n[+],>[1];
struct parts
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 3/32
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 4/32
c<";
print(#3nc ater hile is 4d#,c);
hile( dF)
d<";
or(i"a;i6"b;i77,c77,d77)
{
i(c"")
{
m[0]7"1;
c"0;
i(d"")
{
d"0;
print(#3n'art: 4c4c4d, ear: 4d, $aterial: 4s, Guantity:
4d#,m[0],m[0],d71,p[i]8year,p[i]8material,p[i]8>ty);
print(#3nEey > to >uit or any other key to continue3n#);
scan(#4s#,>);
i(>[0]""11+)
break;
Chap10[D]e Displaying data in structure with condition
)here is a structure called employee that holds information li/e employee code,
name, date of joining# &rite a program to create an array of the structure and
enter some data into it# )hen as/ the user to enter current date# Display the names
of those employees whose tenure is 0 or more than 0 years according to the given
current date#
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 5/32
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 6/32
years#,e[i]8code,e[i]8name);
print(#3nEey > to >uit or any other key to continue3n#);
scan(#4s#,j);
i(j[0]""11+)
break;
unccheck(char ?date,char ?datej)
{
int a,a1,i,t;
or(i"B,t"1,a"0;iF+;i<<,t?"10){
a"a7((?(date7i)<.*)?t);
or(i"B,t"1,a1"0;iF+;i<<,t?"10)
{
a1"a17((?(datej7i)<.*)?t);
i(a<a1F+)
return(1);
else i(a<a160)
return(0);
or(i"+,a"0,t"1;iF1;i<<,t?"10)
{
a"a7((?(date7i)<.*)?t);
or(i"+,a1"0,t"1;iF1;i<<,t?"10)
{a1"a17((?(datej7i)<.*)?t);
i(a<a1F0)
return(1);
else i(a<a160)
return(0);
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 7/32
or(i"1,a"0,t"1;iF"0;i<<,t?"10)
{
a"a7((?(date7i)<.*)?t);
or(i"1,a1"0,t"1;iF"0;i<<,t?"10)
{
a1"a17((?(datej7i)<.*)?t);
i(a<a1F"0)
return(1);
else i(a<a160)
return(0);
Chap10[D]g Use structure to check dates
&rite a program that compares two given dates# )o store date use structure say
date that contains three members namely date, month and year# 1f the dates are
e*ual then display message as 23*ual2 otherwise 24ne*ual2#
void main()
{
int i,"0;
struct date
{
int date;
int month;
int year;
;
struct date d[2];
or(i"0;i62;i77){
print(#3nnter day or the 4d) date3n#,i71);
scan(#4d#,5d[i]8date);
print(#3nnter the month or the 4d) date3n#,i71);
scan(#4d#,5d[i]8month);
print(#3nnter the year or the 4d) date3n#,i71);
scan(#4d#,5d[i]8year);
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 8/32
i(d[0]8date""d[1]8date)
{
i(d[0]8month""d[1]8month)
{i(d[0]8year""d[1]8year)
{
"1;
i(""1)
print(#3nHhe dates are e>ual#);
else
print(#3nHhe dates are not e>ual#);
(a) Create a structure to specify data on students givenbelow:Roll number, Name, Department, Course, Year of joiningssume t!at t!ere are not more t!an "#$ students in t!ecollage%(a) &rite a function to print names of all students w!ojoined in a particular year%(b) &rite a function to print t!e data of a student w!oseroll number is given%
olution!
/* NOTE: since number of students to be assumed is too much ( about 450 )I have alloted full sie (about 450) to it but arra! has been "e#t em#t!$
if !ou have time then !ou can fill u# all 450 names and can search throu%h
them&#ro%ram has been tested b! me and it 'or"s accuratel!& !ou can reduce
the sie of arra! of structure convenientl! b! chan%in% the value of N */
includestdio&h
includeconio&h
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 9/32
define N 450
struct students +
int rlnm,
char name-.5,
char de#t-.5, /* structure defined outside of main(), */ char course-.5,
int !ear,
,
void main() + /* main() */
struct students s-N,
int i$ch,
clrscr(),
/* ta"in% in#ut of 450 students in an arra! of structure */
for(i10,iN,i22) +
#rintf(3 Enter data of student dtttttotal students: dn3$i26$N),
#rintf(3****************************nn3),
#rintf(3enter rollnumber: 3),
scanf(3d3$7s-i&rlnm),
#rintf(3nnenter name: 3),
scanf(3 s3$7s-i&name),
#rintf(3nnenter de#artment: 3),
scanf(3s3$7s-i&de#t),
#rintf(3nnenter course: 3),
scanf(3s3$7s-i&course),
#rintf(3nnenter !ear of 8oinin%: 3),
scanf(3d3$7s-i&!ear),
clrscr(),
/* dis#la!in% a menu */
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 10/32
#rintf(3ntenter !our choice: n3),
#rintf(3t**********************nn3),
#rintf(36: enter !ear to search all students 'ho too" admission in that:nn3),
#rintf(3.: enter roll number to see details of that studentnnn3),
#rintf(3!our choice: 3), /* ta"in% in#ut of !our choice */
scanf(3d3$7ch),
clrscr(),
s'itch(ch) +
case 6:
clrscr(),
dis#!r(7s), /* function call to dis#la! names of students 'ho 8oined in a #articular !ear */
brea",
case .:
clrscr(),
dis#rl(7s), /* function call to dis#la! information of a student
'hose roll number is %iven */
brea",
default:
#rintf(3nnerror9 'ron% choice3),
%etch(),
/******************* main() ends **************/
dis#!r(struct students *a) + /* function for dis#la!in% names of students
'ho too" admission in a #articular !ear */
int 8$!r,
#rintf(3nenter !ear: 3),
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 11/32
scanf(3d3$7!r),
#rintf(3nnthese students 8oined in dnn3$!r),
for(810,8N,822) +
if(a-8&!ear11!r) +
#rintf(3nsn3$a-8&name),
return 0,
dis#rl(struct students *a) + /* function to #rint information of a student 'hose roll number has been
%iven& */
int "$rl,
#rintf(3nenter roll number: 3),
scanf(3d3$7rl),
for("10,"N,"22) +
if(a-"&rlnm11rl) +
#rintf(3nnt etails of roll number: dn3$a-"&rlnm),
#rintf(3t***************************nn3),
#rintf(3 Name: sn3$a-"&name),
#rintf(3 e#artment: sn3$a-"&de#t),
#rintf(3 ;ourse: sn3$a-"&course),
#rintf(3<ear of 8oinin%: d3$a-"&!ear),
brea",
else +
#rintf(3n=oll number !ou entered does not e>istnn3),
brea",
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 12/32
return 0,
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(b) Create a structure to specify data of customers in aban'% !e data to be stored is: ccount number, Name,alance in account% ssume ma*imum of +$$ customersin t!e ban'%(a) &rite a function to print t!e ccount number andname of eac! customer wit! balance below Rs% $$%
(b) -f a customer re.uest for wit!drawal or deposit, it isgiven in t!e form:cct% no, amount, code ( for deposit, $ for wit!drawal)&rite a program to give a message, /!e balance isinsufficient for t!e specified wit!drawal0%
olution!
/* NOTE: since number of customers to be assumed is too much ( about .00 )
I have alloted full sie (about .00) to it but arra! has been "e#t em#t!$
if !ou have time then !ou can fill u# all .00 names and can search throu%h
them&#ro%ram has been tested b! me and it 'or"s accuratel!& !ou can reduce
the sie of arra! of structure convenientl! b! chan%in% the value of N */
includestdio&h
includeconio&h
define N .00
struct ban" +
int acn,
char name-.0,
int bal, /* defined out of main() */
,
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 13/32
void main() +
struct ban" b-N,
int i$ch$l'1600$ch.$ac$am,
clrscr(),
for(i10,iN,i22) + /* in#uttin% customer data */
#rintf(3tEnter information of customers n3),
#rintf(3t******************************nn3),
#rintf(3enter account no&: 3),
scanf(3d3$7b-i&acn),
#rintf(3nnenter customer name: 3),scanf(3s3$7b-i&name),
#rintf(3nnenter balance: 3),
scanf(3d3$7b-i&bal),
clrscr(),
clrscr(),
#rintf(3tEnter !our choicen3), /* further #rocessin% of transaction */
#rintf(3t*****************nn3),
#rintf(36: to "no' 'hose balance is belo' 600&nn3),
#rintf(3.: to #rocess re?uest or 'ithdra'l&nnn3),
scanf(3d3$7ch),
s'itch(ch) +
case 6:
clrscr(),
dis#(7b), /* dis#la!in% 'hose balance is belo' 600 */
brea",
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 14/32
case .:
clrscr(),
#rintf(3enter !our account number: 3),
scanf(3d3$7ac),
for(i10,iN,i22) +
if((b-i&acn)11ac) +
clrscr(),
#rintf(3t@ello sn3$b-i&name), #rintf(3nn3),
#rintf(3nnenter !our choicen3),
#rintf(3n6: de#osite:n3),
#rintf(3n0: 'ithdra'l:nn3),
scanf(3d3$7ch.),
s'itch(ch.) +
case 0:
clrscr(),
if(b-i&ball') +
#rintf(3nnsorr!9 account balance is too lo' for 'ithdra'l&n3),
brea",
else +
#rintf(3nnenter amount for 'ithdra'l: 3),
scanf(3d3$7am),
if(b-i&balam) +
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 15/32
#rintf(3nn!ou donAt have enou%h balance for 'ithdra'l&n3),
else +
b-i&bal1b-i&bal2am,
#rintf(3nn'ithdra'l 'as successful&n3),
brea",
case 6:
clrscr(),
#rintf(3nnenter amount to de#osite: 3),
scanf(3d3$7am),
b-i&bal1b-i&bal2am,
#rintf(3nncash de#osited successfull!&nn3),
brea",
%etch(),
dis#(struct ban" *a) +
int ",
#rintf(3t;ustomers 'hose balance is belo' 600:n3),
#rintf(3t*************************************nn3),
for("10,"N,"22) +
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 16/32
if((a-"&bal)600) +
#rintf(3.dtsn3$a-"&acn$a-"&name),
return 0,
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(c) n automobile company !as serial number for engineparts starting from $ to 112% !e ot!er c!aracteristics
of parts to be specified in a structure are: Year ofmanufacture, material and .uantity manufactured%(a) 3pecify a structure to store information correspondingto a part%(b) &rite a program to retrieve information on parts wit!serial numbers between and CC4%
olution!
includestdio&h
includeconio&h
struct automob +
char name-5,
int !ear,
char mtr-60,
int ?t!,
,void main() +
struct automob a-541++3BB63$.00C$3BBB3$60$
+3BB.3$.00C$3BBB3$60$
+3BBD3$.00C$3BBB3$60$
+3BB43$.00C$3BBB3$60$
+3BB53$.00C$3BBB3$60$
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 17/32
+3BB3$.00C$3BBB3$60$
+3BBF3$.00C$3BBB3$60$
+3BBG3$.00C$3BBB3$60$
+3BBC3$.00C$3BBB3$60$
+3HH63$.060$3HHH3$66$
+3HH.3$.060$3HHH3$66$+3HHD3$.060$3HHH3$66$
+3HH43$.060$3HHH3$66$
+3HH53$.060$3HHH3$66$
+3HH3$.060$3HHH3$66$
+3HHF3$.060$3HHH3$66$
+3HHG3$.060$3HHH3$66$
+3HHC3$.060$3HHH3$66$
+3;;63$.066$3;;;3$6.$
+3;;.3$.066$3;;;3$6.$
+3;;D3$.066$3;;;3$6.$
+3;;43$.066$3;;;3$6.$+3;;53$.066$3;;;3$6.$
+3;;3$.066$3;;;3$6.$
+3;;F3$.066$3;;;3$6.$
+3;;G3$.066$3;;;3$6.$
+3;;C3$.066$3;;;3$6.$
+363$.06.$33$6D$
+3.3$.06.$33$6D$
+3D3$.06.$33$6D$
+343$.06.$33$6D$
+353$.06.$33$6D$
+33$.06.$33$6D$+3F3$.06.$33$6D$
+3G3$.06.$33$6D$
+3C3$.06.$33$6D$
+3EE63$.06D$3EEE3$64$
+3EE.3$.06D$3EEE3$64$
+3EED3$.06D$3EEE3$64$
+3EE43$.06D$3EEE3$64$
+3EE53$.06D$3EEE3$64$
+3EE3$.06D$3EEE3$64$
+3EEF3$.06D$3EEE3$64$
+3EEG3$.06D$3EEE3$64$+3EEC3$.06D$3EEE3$64$
+363$.064$33$65$
+3.3$.064$33$65$
+3D3$.064$33$65$
+343$.064$33$65$
+353$.064$33$65$
+33$.064$33$65$
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 18/32
+3F3$.064$33$65$
+3G3$.064$33$65$
+3C3$.064$33$65,
int i$8$",
clrscr(),
#rintf(3Information of #arts bet'een HH6 to ;;:nn3),
#rintf(3nnNamett!ear(manu&)ttmaterialt?uantit!nnn3),
for(i10,i54,i22) +
if(i1C 77 i1.D) +
#rintf(3Dstt4dttt5stt4dn3$a-i&name$a-i&!ear$a-i&mtr$a-i&?t!),
%etch(),
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(d) record contains name of cric'eter, !is age, numberof test matc!es t!at !e !as played and t!e average runst!at !e !as scored in eac! test matc!% Create an array of structure to !old records of +$ suc! cric'eter and t!enwrite a program to read t!ese records and arrange t!em
in ascending order by average runs% 5se t!e .usort( )standard library function%
olution!
includestdio&h
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 19/32
includeconio&h
includestrin%&h
void main() +
struct cric"eter +
char name-50,
int a%e,
int match,
float avrn,
,
struct cric"eter c-.0$tem#,
int i$8,
clrscr(),
for(i10,i.0,i22) +
#rintf(3Enter data of cric"eter dnnn3$i26),
fflush(stdin),
#rintf(3Name: 3),
%ets(c-i&name),
#rintf(3nnB%e: 3),
scanf(3d3$7c-i&a%e),
#rintf(3nnJatches: 3),
scanf(3d3$7c-i&match),
#rintf(3nnBvera%e runs: 3),
scanf(3f3$7c-i&avrn),
clrscr(),
/*******************//* sortin% records */
/*******************/
for(i10,i.0,i22) +
for(81i26,8.0,822) +
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 20/32
if(c-i&avrn c-8&avrn) +
tem#1c-i,
c-i1c-8,
c-81tem#,
#rintf(3Korted records:nn3),
for(i10,i.0,i22) +
#rintf(3dtstdtdtfnnn3$i26$c-i&name$c-i&a%e$c-i&match$c-i&avrn),
%etch(),
lin"float() +
float a10$*b,
b17a,
a1*b,
return 0,
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(e) !ere is a structure called employee t!at !oldsinformation li'e employee code, name, date of joining%&rite a program to create an array of t!e structure and
enter some data into it% !en as' t!e user to entercurrent date% Display t!e names of t!ose employeesw!ose tenure is 6 or more t!an 6 years according to t!egiven current date%
olution!
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 21/32
includestdio&h
includeconio&h
define N D
void main() +
struct em#lo!ee +
int code,
char name-.0,
int dd$mm$!!,
e-N,
int d$m$!$i,
clrscr(),
for(i10,iN,i22) +
#rintf(3tEnter em#lo!ee data:n3),
#rintf(3t*********************n3),
#rintf(3nEnter em#lo!ee code: 3),
scanf(3d3$7e-i&code),
#rintf(3nnEnter em#lo!ee name: 3),
scanf(3s3$7e-i&name),
#rintf(3nnEnter date of 8oinin% (dd mm !!): 3),scanf(3ddd3$7e-i&dd$7e-i&mm$7e-i&!!),
clrscr(),
clrscr(),
#rintf(3nenter current date(dd mm !!): nn3),
scanf(3ddd3$7d$7m$7!),
clrscr(),
for(i10,iN,i22) +
if((!L(e-i&!!))1D) +
#rintf(3snN3$e-i&name),
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 22/32
%etch(),
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(f) &rite a menu driven program t!at depicts t!e wor'ingof a library% !e menu options s!ould be:% dd boo' information
+% Display boo' information6% 7ist all boo's of given aut!or"% 7ist t!e title of specified boo'#% 7ist t!e count of boo's in t!e library4% 7ist t!e boo's in t!e order of accession number8% 9*itCreate a structure called library to !old accessionnumber, title of t!e boo', aut!or name, price of t!e
boo', and flag indicating w!et!er boo' is issued or not%
olution!
includestdio&h
includeconio&h
includedos&h
void main() +
struct librar! +
int acn,
char title-.5,
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 23/32
char auth-.5,
float #rice,
int fla%,
,
struct librar! a-51+ +.$3BBB3$3BBB3$654&G$6$
+6$3HHH3$3HHH3$6.4&$0$
+5$3EEE3$3EEE3$.D4&D$0$
+D$3;;;3$3;;;3$.D.&D$6$
+4$33$33$6.6&D$0
,
struct librar! tem#, /* tem#orar! structure to over'rite information /
and for assistance in sortin% the 'hole structure */
int i$ch$"$fla%$810,
char author-60,
clrscr(),
'hile(6) + /* initialied an indefinite loo# */
clrscr(),
#rintf(3t6: Bdd boo" informationn3),#rintf(3t.: is#la! boo" informationn3),
#rintf(3tD: Mist all boo"s of %iven authorn3),
#rintf(3t4: Mist the title of s#ecified boo"n3),
#rintf(3t5: Mist the count of boo"s in the librar!n3),
#rintf(3t: Mist the boo"s in order of accesion numbern3),
#rintf(3tF: E>itnnn3),
#rintf(3;hoice: 3),
scanf(3d3$7ch),
s'itch(ch) +
case 6: /* addin% boo" information over current information */
clrscr(),
#rintf(3tt6: Bdd boo" information:nnn3),
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 24/32
#rintf(3enter boo" information:nn3),
#rintf(3Bccesion number of boo" to be modified: 3),
scanf(3d3$78), fflush(stdin),
for(i10,i5,i22) +
if(811a-i&acn) +
#rintf(3nnenter ne' information:nn3),
#rintf(3accesion no&: 3),
scanf(3d3$7tem#&acn), fflush(stdin),
#rintf(3nntitle: 3),
scanf(3s3$7tem#&title), fflush(stdin),
#rintf(3nnauthor: 3),
scanf(3s3$7tem#&auth), fflush(stdin),
#rintf(3nn#rice: 3),scanf(3f3$7tem#&auth), fflush(stdin),
#rintf(3nnfla%(6/0): 3),
scanf(3d3$7tem#&fla%), fflush(stdin),
a-81tem#, /* over'ritin% current information 'ith ne' one */
clrscr(),
#rintf(3nnInformation added succesfull!9nn3),
dela!(.000),
brea",
case .: /* dis#la!in% current boo" information */
clrscr(),
#rintf(3tt.: is#la! boo" information:nnn3),
#rintf(3Enter accesion number: 3),
scanf(3d3$7"),
for(i10,i5,i22) +
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 25/32
if("11a-i&acn) +
clrscr(),
#rintf(3Hoo" information: nn3),
#rintf(3nnBccesion Number: d3$a-i&acn),
#rintf(3nTitle: s3$a-i&title),#rintf(3nButhor: s3$a-i&auth),
#rintf(3nrice: f3$a-i&#rice),
if(a-i&fla%110) +
#rintf(3nla%: Not issuednn3),
else+
#rintf(3nla%: Issuednn3),
dela!(6000),
brea",
case D: /* listin% all boo"s of %iven author */
clrscr(),
#rintf(3ttD: Mist all boo"s of %iven author:nnn3),
#rintf(3Enter author name: 3),
scanf(3s3$7author), fflush(stdin),
#rintf(3nnboo"s of snn3$author),
for(i10,i5,i22) +
"1strcm#(author$a-i&auth),
if("110) +
81826,#rintf(3d&tsn3$8$a-i&title),
dela!(.000),
brea",
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 26/32
case 4: /* dis#la!in% title of %iven boo" */
clrscr(),
#rintf(3tt4: Title of the s#ecified boo":nnn3),
#rintf(3Enter the accesion number: 3),
scanf(3d3$7"),
#rintf(3nn3),
for(i10,i5,i22) +
if("11a-i&acn) +
#rintf(3Title: sn3$a-i&title),
dela!(.000),
brea",
case 5: /* countin% total boo"s in librar! */
clrscr(),#rintf(3tt5: Mist the count of boo"s in the librar!: nnn3),
for(i10,i5,i22) +
81826,
#rintf(3tTotal boo"s: .d3$8),
dela!(.000),
brea",
case : /* sortin% the boo"s b! their accesion numbers */
clrscr(),
#rintf(3: Mist the boo"s in order of accesion number: nnn3),
for(i10,i5,i22) +
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 27/32
for(81i26,84,822) +
if(a-i&acna-8&acn) +
tem#1a-i,
a-i1a-8,a-81tem#,
#rintf(3Bccess no&tTitletButhortla%nnn3),
for(i10,i5,i22) +
#rintf(34dtt5st5st3$a-i&acn$a-i&title$a-i&auth),
if(a-i&fla%110)#rintf(3not issuednn3),
else
#rintf(3issuednn3),
dela!(.000),
brea",
case F: /* condition for %oin% out */
e>it(),
lin"float() + /* s#ecial function to solve com#ilar error */
float a10$*b, /* not used 'ithin% the #ro%ram but still defined */
b17a,a1*b,
return 0,
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 28/32
(g) &rite a program t!at compares two given dates% ostore date use structure say date t!at contains t!reemembers namely date, mont! and year% -f t!e dates are
e.ual t!en display message as 9.ual ot!erwise5ne.ual%
olution!
includestdio&h
includeconio&h
void main() +
struct date +
int date,
int month,
int !ear,
d6,
int d$m$!$i,
clrscr(),
#rintf(3enter the date to save in structure: nn3),
#rintf(3Enter the date: 3),
scanf(3d3$7d6&date),
#rintf(3nnEnter the month: 3),
scanf(3d3$7d6&month),
#rintf(3nnEnter the !ear: 3),
scanf(3d3$7d6&!ear),
clrscr(),
#rintf(3nenter the date to com#are 'ith structure:nn3),
#rintf(3Enter the date: 3),
scanf(3d3$7d),
#rintf(3nnEnter the month: 3),
scanf(3d3$7m),
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 29/32
#rintf(3nnEnter the !ear: 3),
scanf(3d3$7!),
if(d11d6&date 77 m11d6&month 77 !11d6&!ear) +
#rintf(3nndates are e?ualnn3),
else +
#rintf(3nndates are une?ualnn3),
%etch(),
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(!) 7in'ed list is a very common data structure oftenused to store similar data in memory% &!ile t!e elementsof an array occupy contiguous memory locations, t!ose of
a lin'ed list are not constrained to be stored in adjacentlocation% !e individual elements are stored/somew!ere0 in memory, rat!er li'e a family dispersed,but still bound toget!er% !e order of t!e elements ismaintained by e*plicit lin's between t!em% !us, alin'ed list is a collection of elements called nodes, eac!of w!ic! stores two item of information;an element oft!e list, and a lin', i%e%, a pointer or an address t!at
indicates e*plicitly t!e location of t!e node containingt!e successor of t!is list element%&rite a program to build a lin'ed list by adding newnodes at t!e beginning, at t!e end or in t!e middle of
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 30/32
t!e lin'ed list% lso write a function display( ) w!ic!display all t!e nodes present in t!e lin'ed list%
olution!
includestdio&h
includeconio&h
includealloc&h
includect!#e&h
struct lin"list +
int data,
lin"list *lin",
,
void main() +
struct lin"list *first$ *tem#,
char choice1A!A,
int count10,
clrscr(),
/* ta"in% the in#ut of first element */
#rintf(3Enter element d: 3$22count),
first1(lin"list *)malloc(sieof(lin"list)),
scanf(3d3$7firstLdata),
firstLlin"1NMM,
#rintf(3nnEnter another element(</N): 3),
choice1%etche(),
tolo'er(choice), /* convertin% to lo'ercase to match the condition of s'itch */
s'itch(choice) +
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 31/32
case A!A:
clrscr(),
'hile(choice11A!A PP choice11A<A) +
#rintf(3nEnter element d: 3$22count),
tem#1(lin"list *)malloc(sieof(lin"list)),
scanf(3d3$7tem#Ldata),
tem#Llin"1first,
first1tem#,
#rintf(3nnnEnter another elements(</N): 3),
choice1%etche(),
clrscr(),
brea",
case AnA:
brea",
#rintf(3nTotal elements 1 dnn3$count),
/* #rintin% all elements */
for(tem#1first, tem#91NMM, tem#1tem#Llin") +
#rintf(3d 3$tem#Ldata),
7/21/2019 C Chapter 10
http://slidepdf.com/reader/full/c-chapter-10 32/32
%etch(),
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<