Вы находитесь на странице: 1из 9

Practices Assignment C++ : Structures

Submitted By : Nita arora KHMS

Practices Assignment C++ : Structures


S.NO. Q1. Sub Part (a) Find the errors if any: Question Marks

void main() { struct data { int roll =0; struct data1 { float phy; }x; x.phy=90; }y; cout<<y.roll<< <<y.phy; }
(b)
(a) Rewrite the following program after removing all syntactical

(2)

error(s), if any. Underline each

correction.

#include<iostream.h> int main() { structure student { int. rno, mark; }stu; student stuA= (1001,49); student stuB= stuA; if (stuA!= stuB) stuA.mark= 55; else stuB.mark= 25; cout<<stuA.mark<<stub.mark; }
(c) What will be the output of the following code:struct Item { int I_no; char I_name[20]; float I_price; int I_qty; }; void main() { Submitted By : Nita arora KHMS

Practices Assignment C++ : Structures


Item S[4]= {{1,Bread,11.0,20}, {2, Butter,25.0,40}, {3,Cream,65,15}, {4,Jam,95.5,20}}; cout<<S[0].I_no; cout<<S[1].I_name[4]; cout<<S[2].I_qty; cout<<S[3].I_name;

(d)

Find the output of the following program: 3 #include <iostream.h> struct GAME { int Score; int Bonus; }; void Play(GAME &g, int N=10) { g.Score++;g.Bonus+=N; } void main() { GAME G={110,50}; Play(G,10); cout<<G.Score<<":"<<G.Bonus<<endl; Play(G); cout<<G.Score<<":"<<G.Bonus<<endl; Play(G,15); cout<<G.Score<<":"<<G.Bonus<<endl; }

(e)

Rewrite the following program after removing all syntactical error(s), if any. Underline each correction. #include<iostream.h> int main() { structure student { int. rno, mark; }stu; student stuA= (1001,49); student stuB= stuA; if (stuA!= stuB) stuA.mark= 55; else stuB.mark= 25; cout<<stuA.mark<<stub.mark;
Submitted By : Nita arora KHMS

(2)

Practices Assignment C++ : Structures


}
(f) Rewrite the following program after removing the syntactical error(s), if any. Underline each correction. #include <iostream.h> void main( ) { struct movie { char movie_name [20]; char movie type; int ticket cost = 100; }MOVIE; gets(movie_name); gets(movie_type); } (g) Rewrite the following program after removing the syntactical errors (if any). Underline each correction. 2 #include <iostream.h> struct Pixels { int Color,Style;} void ShowPoint(Pixels P) { cout<<P.Color,P.Style<<endl;} void main() { Pixels Point1=(5,3); ShowPoint(Point1); Pixels Point2=Point1; Color.Point1+=2; ShowPoint(Point2); } Find the output of the following program: #include <iostream.h> struct Game { char Magic[20]; int Score; }; void main() { Game M={Tiger,500}; char *Choice; Choice=M.Magic; Choice[4]=P; Choice[2]=L; M.Score+=50; Submitted By : Nita arora KHMS (2)

(h)

Practices Assignment C++ : Structures


cout<<M.Magic<<M.Score<<endl; Game N=M; N.Magic[0]=A;N.Magic[3]=J; N.Score-=120; cout<<N.Magic<<N.Score<<endl; (i) } Find the output of the following program
#include <iostream.> struct three_d; {int x,y,z;} void movein(three_d &t, int step=1) {t.x + = step; t.y - = step; t.z + = step; } void moveout(three_d &t, int step=1) {t.x - = step; t.y + = step; Study Material 2010-11 -- 25 -- Computer Science -XII t.z - = step; } void main( ) {three_d t1={10,20,5}, t2=(30,10,40}; movein(t1); moveout(t2,5); cout<<t1.x<<,<<t1.y<<,<<t1.z<<endl; cout<<t2.x<<,<<t2.y<<,<<t2.z<<endl; movein(t2,10); cout<<t2.x<<,<<t2.y<<,<<t2.z<<endl; } Solution : 11, 19, 6 25, 15, 35 35, 5, 45 Find the output of the following program: #include <iostream.h> struct PLAY { int Score, Bonus; }; void Calculate(PLAY &P, int N=10) {P.Score++; P.Bonus += N; } void main() {PLAY PL={10,15}; Calculate(PL, 5); cout<<PL.Score<<:<<PL.Bonus<<endl; Calculate(PL); cout<<PL.Score<<:<<PL.Bonus<<endl; Calculate(PL,15); cout<<PL.Score<<:<<PL.Bonus<<endl; }

(j)

(k)

Find the output of following program:


Submitted By : Nita arora KHMS

Practices Assignment C++ : Structures


struct Teacher { int TrId; char Trname[20]; float Salary: } T[3]={{1101, Avinsash, 6500.00}, {1102, Manpreet,7500.00}, {1103, Saurabh, 6600.00} }; void main( ) { cout<<T[0].Salary<<\n; cout<<T[1].Trname<<\n; cout<<T[2].TrId<<\n; cout<<T[2].salary<<\n; } Find the output of following program:
struct Game { char Gname[20]; float Gduration; int No_Of_Players; }

G[4]={{Cricket,7,11}, {Kabaddi,2, 7}, {Football,2, 11}, {Hockey,2,11} }; void main( ) { cout<<G[3].Gname<<\n;


Submitted By : Nita arora KHMS

Practices Assignment C++ : Structures


cout<<G[1].Gduration<\n; cout<<G[2].No_Of_Players<<\n; cout<<G[0].Gname[5]<<\n; }
struct Invoice { int Cust_No; char Cust_Name[20]; float Unit_Price; }

I[2]={{101, Avinsash, 650.00}, {102, Manpreet,750.00}, {103, Saurabh, 660.00} }; void main( ) { cout<<I[0].Cust_No<<\n; cout<<I[0].Cust_Name[3]<\n; cout<<I[1].Unit_Price<<\n; cout<<I[2].Cust_Name<<\n; }
Find the output of the following program : #include<iostream.h> #include<conio.h> struct triangle { float angle; float base; float height; }; void display(triangle question) { cout<<endl<<base:<<question.base; cout<<endl<<height:<<question.height; cout<<endl<<angle:<<question.angle; } triangle difference(triangle one, triangle & two) Submitted By : Nita arora KHMS

Practices Assignment C++ : Structures


{ triangle three; if(one.base<two.base) { two.height=100; three=two; } else { two.angle=22; three=one; } return three; } void main() { clrscr(); triangle building={20,10,30}, flagstaff, differ; flagstaff = building; flagstaff.height+=5; flagstaff.base+=45; display(building); differ=difference(building, flagstaff); display(differ); display(flagstaff); getch(); }; Ans: Output Base: 10 Height :30 Angle : 20 Base: 55 Height :100 Angle : 20 Base: 55 Height :100 Angle : 20 Q2 (a) Declare a structure time that contains two members- hours and minutes of type integer. Write a function add_time( ) that takes two time as parameters and displays the sum of time (total time). Example Input : time1 Hrs= 2 Minutes = 54 Input : time2 Hrs= 5 Minutes = 20 Output : Total Time : 8 hrs 14 minutes NOTE: Assuming minutes given as input are less than 60 as shown in the example. (b) 1

Consider following structure:


Submitted By : Nita arora KHMS

Practices Assignment C++ : Structures


struct ENGLISH { char WORD[20]; char MEANING[20]; }; Write a function Search_Meaning( )that takes array of ENGLISH, a search_WORD and size of array as parameters and displays the MEANING if word is found otherwise it should display the message Word Not Found.

Submitted By : Nita arora KHMS

Вам также может понравиться