Robert Lafore solution

April 4, 2018 | Author: M Waqas Anwar | Category: C++, Subroutine, Object (Computer Science), Data Type, Object Oriented Programming


Comments



Description

Robert LaforeExercise # 1 Questions 1) Pascal, BASIC and C are procedural languages, while C++ is object oriented language. 2) A widget is to the blue print for a widget as an object is to a) b) c) d) A member function. A class. An operator. A data item. 3) Two major components of an object are data and functions that operate on that data. 4) In C++, a function contained within a class is called, a) b) c) d) A member function. An operator. A class function. A method. 5) Protecting data from access by unauthorized functions is called data hiding. 6) Which of the following are good reasons to use an object oriented language? a) b) c) d) You can define your own data type. Program statements are simple than in procedural languages. An OO program can be taught to correct its own errors. It’s easier to conceptualize an OO program. 7) Objects model entities in the real world more closely than do functions. 8) True or False: A C++ program is similar to a C program expect for the details of coding. 9) Bundling data and functions together is called encapsulation. 10) When a language has the capability to produce new data types , it is said to be a) b) c) d) Reprehensible. Encapsulated. Overloaded. Extensible. 11) True or False: You can easily tell from any two lines of code, whether a program is in C++ or in C. 12) The ability of a function or operator to act in different ways on different data types is called polymorphism. 6) Write an example of a normal C++ comment and an example of an old-fashioned comment. Classified. . A way to look at the organization of a program. Encapsulated. Mau be part of a statement. 15) The unified Modeling language is. Overloaded. Always occurs outside a function. May reduce the size of the program. Old-fashioned = \* this is an old-fashioned comment*\. 7) An expression a) b) c) d) Usually evaluates to a numerical value. 3) A function body is defined by braces { }. Completely irrelevant.13) A normal C++ operator that acts in special ways on newly defined data types is said to be. The combination of C++ and FORTRAN. Exercise # 2 2) A function body must be followed by parentheses. Normal = \\this is a normal comment. a) b) c) d) Critically important. a) b) c) d) Glorified. a) b) c) d) A program that builds physical models. Ans. Makes the program run faster. Robert Lafore Questions 1) Dividing a program into functions a) b) c) d) Is the key to object-oriented programming Makes the program easier to conceptualize. Indicates the emotional state of the program. 5) A C++ instruction that tells the computer to do something is called a statement. 14) Memorizing the new terms used in C++ is. Something you can return to later. It is the first function executed when the program starts. Helpful in developing software systems. 4) Why is the main( ) function special? Ans. The key to wealth and success. 19) The expression 11%3 evaluates to 2.8) Specify how many bytes are occupied by the following data types in 32-bit system: a) b) c) d) Type int = 4 Type float = 4 Type long double = 10 Type long = 4 9) True or False: A variable of type char can hold the value 301. the value on the left of the equal sign is always equal to the value on the right side. b) ‘a’ character constant.h>. b) The name jim = cout<<”jim”. <iomanip. c) The number 509 = cout<<”509”. 16) What header file must you #include with your program to use setw? Ans./) 21) Write a statement that uses an arithmetic assignment operator to increase the value of the variable temp by 23. Ans. 18) True or false: it’s perfectly all right to use variables of different data types in the same arithmetic expression. 20) An arithmetic assignment operator combines the effect of what two operators? Ans. Write the same statement without the arithmetic assignment operator.-. <iostream. Cout<<setw(10)<<George. Ans. 10) What kind of program elements are the following? a) 12 = integer constant. 11) Write a statement that display on the screen. d) Junglejim ( ) = function name. c) Junglejim = variable name or identifier. 17) Two exceptions to the rule that the compiler ignores whitespace are the string constant and preprocessor directives. 13) Write a statement that displays the variable George in a field ten characters wide. Cin>>temp.h> 15) Write a statement that gets a numerical value from the key board and plaaces it in the variable temp. 14) What header file must you #include with your source file to use cout and cin? Ans. a) The character ‘x’ = cout<<”x”. 12) True or False: in an assignment statement.*. Assignment (=) and arithmetic (+. . cout<<a<<"\n"<<b<<"\n"<<c. long double g. int a=10. 20 & 20 each time. Exercises Q 1 Answer) #include<constream.c. Ans. getch().h> void main() { clrscr(). getch(). Without arithmetic assignment operator temp = temp + 23.134. What will be the following code print out? cout<<var1--. objects and over loaded operators. c=b-1. Header files are used for declaration. It increases by 1. getch(). 22) The increment operator increases the value of a variable by how much? Ans. 25) The actual code for library functions is contained in a library file. cout<<"\nThe cube feet are\t\a"<<g*0. } Q 2 Answer) #include<constream.Ans. cin>>g. data for library. 23) Assuming var1 starts with the value of 20. With arithmetic assignment operator temp + = 23. //g stands for gallons cout<<"please enter the number of gallons\n\t". cout<<"\n1990\t135\n1991\t7290\n1992\t11300\n1993\t16200".h> void main() { clrscr(). 24) In the example we have seen so far header files have been used for what purpose? Ans. b=a*2. } . } Q 3 Answer) #include<constream. cout<<++var1.h> void main() { clrscr().b. getch(). cout<<"\n\tYour amount in japani yens is = "<<y<< "Yens".y. y=d*104.". long double d. p=d*0.S $\n\t". cout<<"\n\tYour amount in Germen Duetschemark is = "<<g<<" Duetschemark".814.g. cout<<"\n\tYour amount in francs is = "<<f<<" Francs". cout<<" enter a lower case letter\n\t".p.\n\n\thow i wonder what you are. } Q 6 Answer) #include<constream. cout<<"\n\t"<<islower(a). } Q 5 Answer) #include<constream.h> void main() { clrscr(). f for franc.712.672. char a. getch(). getch().\n\nTwinke twinkle little star.h> #include<ctype. cin>>d. g for germen and y for yen. g=d*1. p for pounds.\n\nup above up so high. f=d*5.\n\n\tLike a diamond in the sky.//d for dollars.h> void main() { clrscr(). cout<<"\n\tYour amount in pounds is = "<<p<<" Pounds". } .172. cout<<"\n\tMy Favorite Poem\n\nTwinke twinkle little star.\n\n\tHow i wonder what you are.f. cin>>a.Q 4 Answer) #include<constream. cout<<"\tPlease Enter your amount in U.h> void main() { clrscr(). b.c. cout<<"\nenter 2nd fraction's nominator\t". cout<<a<<"/"<<b<<"+"<<c<<"/"<<d<<" = "<<(a*d+b*c)/(b*d). cin>>c. getch(). cout<<"\n\tTemper in Fahrenheit is = "<<9*(c+32)/5<<" Degrees". cout<<"\nenter first fraction's nominator\t".h> void main() { clrscr(). cout<<"portcity"<<setw(18)<<setfill(3)<<"2425785". long double c. cin>>d. } . cout<<"\nenter 2nd fraction's denominator\t". long double a. getch(). cin>>c.h> void main() { clrscr(). cout<<"\nenter first fraction's denominator\t". cin>>b. cout<<"\n\tEnter temperature in celsius\t".h> void main() { clrscr(). } Q 9 Answer) #include<constream.Q 7 Answer) #include<constream. } Q 8 Answer) #include<constream. cin>>a.d. getch().h> #include<iomanip. h> void main() { clrscr().decfrac. pounds=decpounds. Q 11 Answer) #include<constream. } cout<<"\n\n\aDecimel pounds = \x9c"<<pound<<". . decfrac=decpounds-pounds. cin>>decpounds. cin>>shilling.h> void main() { clrscr(). cout<<"last name"<<setw(3)<<setiosflags(ios::left)<<"First name". int pound.pence. getch().y. } Q 12 Answer) #include<constream. getch(). x=decfrac*20. getch().shilling. cin>>pound. cout<<"\nenter pounds : ". cin>>pence. cout<<"\nenter shillings : ". int pounds. cout<<"Enter decimal pounds :"."<<((shilling*5)-5)+pence.Q 10 Answer) #include<constream. cout<<"\nenter pence : ".h> void main() { clrscr(). float decpounds.h> #include<iomanip.x. } cout<<x. if(x==1) { cout<<"\nEnter temperature in Fahernheit : ". for(y=1.y<=30.h> void main() { clrscr(). int y. cin>>c. cout<<"\n In Fahrenheit it is : "<<(9*c/5)+32<<" Degrees".y++) { cout<<x*y<<"\t". cout<<endl. } getch(). } getch(). cout<<"Type\n\n 1 to convert temperature from Fahrenheit to Celsius\n\n 2 to convert temperature from Celsius to Fahrenheit\n\t".Robert Lafore Exercises Q 1 Answer) #include<constream. cin>>f. cout<<" enter number : ". cout<<"\n In Celsius it is : "<<5*(f-32)/9<<" Degrees". long double f.c. cin>>x. } if(x==2) { cout<<"\nEnter temperature in Celsius : ". } Exercise # 3 Q 2 Answer) #include<constream. long double x. if(y%10==0) cout<<endl. } .h> void main() { clrscr(). int x. cin>>x. unsigned long total=0. break. rows <= 5. } cout<<"\n\tAnswer is : "<<s. case'-' : s=x-y. cin>>ch.h> int main() { clrscr(). int x. for (rows = 0. cout<<"\n\ndo you want to continue enter (Y for yes and N for no)". case'/' : s=x/y. return 0. } Q 5 Answer) #include<constream. do{ cout<<"Enter ist digit .h> void main() { int rows. break. } Q 4 Answer) #include<constream.y. cout<<"Enter six digits". int space. cin>>x>>op>>y.} cout<<"\nNumber is : "<<total<<endl. char ch. rows++) { .peration & 2nd digit\n\t". while((ch=getch())!='\r') {total=total*10+ch-'0'. switch(op) { case'*' : s=x*y. break.h> int main() { clrscr().s. return 0. char op. long double x. break.Q 3 Answer) #include<constream.ch. } while (ch != 'n'). case'+' : s=x+y. space--) { cout << " ". for(w=1. getch(). long double w. y=y/100.w++) { x=x+(x*y).z. space >= rows. } Q 8 Answer) #include<constream. cin>>pnds2.pnds2. cin>>z. cout<<"\nshillings : ". cout<<"\nEnter no.for (space = 5.h> void main() { clrscr().w<=z. cin>>x.sh. do{ cout<<"enter first amount:\npounds : ".y. char ch. cout<<"\npence : ".. x <= rows. cin>>sh. } for (x = 0. cout<<"\nEnter %age\t". cout << endl. Q 7 Answer) #include<constream. int pnds.x. . cout<<"\nEnter amount\t". cout<<"enter 2nd amount:\npounds : ".pnc2. cin>>y.pnc. x++) cout << "X". } getch(). cin>>sh2. cout<<"\nshillings : ". cin>>pnc.y. cin>>pnds.x.h> void main() { clrscr().z. of years\t".sh2. } cout<<"At the end of"<<z<<" years your amonut is : "<<x<<" Dollras". } Q 6 Answer) Could not solve it…. cin>>y. p1=p/100. cout<<"Enter final amount : ". y=sh+sh2.h> void main() { clrscr().x.z--) { w=z*(y-1). cin>>f. getch(). if(y>19) x++. while(i<=f) { i=i+(f*p1). cin>>p. } cout<<"\npossible combinations are : "<<w. x++.p. int w. z--.y. cout<<"\nEnter %age of interest : ".h> void main() { clrscr(). cout<<"Enter the number of chairs : ".z>(y-x). cin>>i.cout<<"\npence : ". cout<<"continue? (Y or N)\n"."<<y<<".z. z=pnc+pnc2. cout<<"\nEnter initial amount : ". x=pnds+pnds2. of guests : ". cin>>x. int x=2. } while(ch!='n'). cin>>ch. if(z>11) y++."<<z. } Q 9 Answer) #include<constream. cout<<"\nEnter the no. cout<<"\nyour ans is : \x9c\n"<<x<<". for(z=y. .p1. cin>>pnc2. long double i.f. } Q 10 Answer) #include<constream. } if(y>19) x++. y=y-20."<<y<<". cin>>pnds. break. y=sh*sh1.x. } { { if(z>11) y++.z.a.d.b. } Q 12 Answer) #include<constream. char op. cout<<"enter first amount:\npounds : ". cout<<"\npence : ".pnc1. case'*' : x=pnds*pnds1. cout<<"\nenter first fraction's denominator\t". cout<<"\nshillings : ". z=pnc-pnc1. cin>>pnc. break. char op. cin>>op. cout<<"\npence : ". z=pnc+pnc1. getch(). cin>>sh1. int pnds. switch(op) { case'+' : x=pnds+pnds1. z=pnc*pnc1. sh.y.sh1.c. cin>>pnds1. cin>>pnc1. cout<<"\nenter 2nd amount:\npounds : ". cin>>a. z=z-12."<<z. .h> void main() { clrscr(). cin>>sh. } Q 11 Answer) #include<constream. cout<<"\nenter first fraction's nominator\t". y=sh+sh1. case'-' : x=pnds-pnds1. long double x. } cout<<"\nNow amountis\x9c"<<x<<". cout<<"\nshillings : ". getch().} cout<<"\n it took "<<x<<" years at interest of "<<p<<" %". cout<<"Enter your desired operation : ".pnds1.y. pnc. y=sh-sh1.h> void main() { clrscr(). break. cin>>b.y=(b*d). cout<<"\nEnter mathematical operator : ". } cout<<"\n"<<a<<"/"<<b<<" "<<op<<" "<<c<<"/"<<d<<" = "<<x<<"/"<<y<<" = "<<x/y. case'-' : x=(a*d-b*c). case'*' :x=a*c. . break. switch(op) { case'+' : x=(a*d+b*c). cin>>c.y=(b*d).break. cin>>d. getch().y=b*d.y=b*c.break. cout<<"\nenter 2nd fraction's denominator\t".break. cout<<"\nenter 2nd fraction's nominator\t". } ………………………………………………………………………………………………………………. cin>>op. case'/' :x=a*d.
Copyright © 2024 DOKUMEN.SITE Inc.