ReviewQuestions
|
UNEDITED QUESTIONS FROM THE STUDENTS Aron Long 1) node = +*x^1 is an extractor. T/F (answer F) 2) i=rand() % 6+1 gives you random numbers from ____ ? a) 0-5 b) 1-5 c) 1-6 d) 0-6 e) none of the above 3) Whats missing in this shuffle program?
int chapters[N]; int i, k, temp; for (i=0; i<N; i++) chapters[i] = i; for (i=0; i<N; i++) { ** mising line ** temp = chapters[i]; chapters[i] = chapters[k]; chapters[k] = temp; } a) k = rand()%N; b) else c) rand()%n = k d) none of the above Answer is A 4) Friend is not a reserved word in C++ ? T/F (ans F ) 5) This is an example of ? void cube(int *p); cube (&n); a) called by value b) called by reference c) called by user d) called by chance e) none of they above Answer is b Chris Yates 1) The process of placing the elements of an array in order is called _____ the array. a)initializing b)sorting c)debuging d)none of the above Answer--b 2) (T or F) It is correct to create overloaded functions with identical parameter lists and different return types. Answer-- False (It is a syntax error) 3) Members of a class specified as _____ are accessible anywhere an object of the class is in scope.
a)private b)public c)friends d)none of the above Answer-- a 4) (T or F) The keywords class and struct. can be used to introduce a class definition. Answer-- True 5) (T or F) Member function of a class are normally made public and data members of a class are normally made private. Answer-- True Gary Erisman True or False 1. To declare a class you must: declare an operation in the public section and define data fields in the private section. Answer: True-both are required. Multiple Choice 2. What is the correct call to the void function void draw(int); a. draw (x,y); b. draw (3); c. y=draw(3); d. none of the above Answer: b 3. To change the value of a parameter inside a function then that parameter should be passed to the function by ________. a. value b. reference c. I don't care d. none of the above Answer: b 4. Fix this function so when "i" is printed it includes 3 and when "j" is printed it includes 4. for(i=2;i<3;i+1) for(j=0;j<4;j=j+2) cout<<i<<j<<endl; Answer: i<=3; and j<=4; True or False 5. Classes make programming in C++ more complicated and confusing. Answer: False - classes organize the program. Jaime Servaes 1. Fix the problem: Class Cat { private: int itsColor; int itsSex; public: int itsAge; int itsWeight; } int main() { Cat Seagram; Seagram.itsSex=Female; cout<< "Seagram is a cat that is ; cout<< "Segram.itsSex<< " ."\n; return0; } Answer: trying to access a private memeber and you can't do that. 2. Leave out part of a line void function1(); void function2(void); int main() { function1(); function2(); return0; } void function1() { cout<< "function1 does nothing" <<end1; } void function2 { cout<< "function2 does nothing also" <<endl; } Answer: void function2 should be written as void function2(void). 3. Name the function int counter=0; counter<10; counter++ while counter<10 { cout<< "counter: " <<counter; } Answer: while loop 4. true-false An array element (e.g., x[1]) is passed as a call-by-value argument to a function. True 5. Multiple Choice A pointer: a. indirectly references a value b. can have a NULL value c. can be used to make a call-by-refernce d. all of the above Answer--D. all the above Jaimee Bohannon 1. The function definition lists the return-value type, the function name and ___________ . a. Parameter list c. Function data type b. A return statement d. None of the above Answer: a
2. T or F C++ programs do not compile unless function prototypes are provided for every function or each function is defined before it is used. Answer: T 3. void f1(const int *xPtr) { *xPtr = 100; } What is the error is function 1? a. *xPtr cannot be greater than 1 b. *xPtr cannot be modified c. *xPtr can be modified d. None of the above Answer: b 4. The sizeof operator when applied to an array name returns the number of __________ in the array. a. number of elements b. number of bits c. number of bytes d. none of the above Answer: c 5. class Time { public: Time (void); void setTime(int, int, int); void printMilitary(void); void printStandard(void); private: int hour; int minute; int second; }; int main () { Time t; t.hour = 7; cout << "minute = " << t.minute; return 0; } What is the error in the preceeding code? a. can't access private members of a class b. can't access public members of a class c. minute and hour are not defined d. time is not a data type e. None of the above answer is a Jennifer Chang 1.What message will be displayed on the screen ? #include <iostream.h> int distance(int velocity=80,int time=30); int main() { cout<<"The distance is:"<<distance(); return 0; } int distance(int velocity,int time) { return (velocity*time); }
a.The distance is:240 b.The distance is:2400 c.The distance is: d.nothing will be displayed ANS: b 2.What will be the best statement in "line 4" to display a matrix below? 1 2 3 4 5 6
1 #include <iostream.h> 2 int main() 3 { 4 ??????????????? 5 for (int i=0;i<3;i++) 6 { for (int j=0;j<2;j++) 7 { cout<<matrix[i][j]; 8 cout<<" "; 9 } 10 cout<<endl; 11 } 12 return 0; 13 } a. int matrix[3][2]={{1,2,3,4},{5,6}}; b. int matrix[3][2]={{1,2,3},{4,5,6}}; c. int matrix[3][2]={{1,2},{3,4},{5,6}}; d. none of the above ANS: c 3.What's the area of this triangle? #include <iostream.h> double TriangleArea(double,double); int TriangleArea(int,int);
int main(void) { cout<<"The area of this triangle is:"<<TriangleArea(5,6)<<endl; return 0; } double TriangleArea(double base,double hight) { return (base*height/2); } int TriangleArea(int base,int hight) { return (base*height/2); } a.30.0 b.15.0 c.30 d.15 ANS: d 4.(T/F) A class's private data members can be manipulated only by public member functions and friend functions. ANS: T 5.(T/F) Statement " const int *sptr; " means a constant pointer to a non-constant integer. ANS: F ,it means a non-constant pointer to a constant data. Jon Ibbetson 1) Memebers of a class specified as __________ are accessible only to member functions of the class and friends of the class. A) default B) private C) public D) none of the above Answer B 2) (T or F) A constructor is a special member functions used to initialize the data members of a class. A)True B)False Answer A (True) 3) The ________ function is used to retrieve values of private data of a class. A)get B)set C)return(); D)none of the above Answer A 4) (T or F) A set function is used to assign values to private data members of a class. A)True B)False Answer A (True) 5) What keyword introduces a structure definition. A)class. B)function C)struct. D)none of the above Answer C Mark Belles Choose the best answer. 1. What is this statement an example of? cout << :: x << endl; a. unary scope resolution operator b. binary scope resolution operator c. southwestern bell operator d. none of the above(statement is incorrect and will cause an error) e. extraction operator Ans. a
(T or F) 2. This is a valid declaration of an array using pointers. char **s = {Pittsburg, Joplin, Fort Scott}; Ans. F (quotes around strings) Fill in the blank. 3. The are ____ methods for declaring pointers. Ans. 4 Choose the best answer. 4. You may declare pointers via the following methods... a. pointer to non-constant data b. pointer to constant data c. constant pointer to constant data d. constant pointer to non-constant data e. all of the above What is wrong with the following code? 5. The following is an example of the switch selection structure. Please circle and correct (any & all) errors, if any exist. //switch structure grade = 'A'; switch (grade) { case'A': ++aCount; break; case'B': bCount++; break; default: cerr<< "Error\n';} Ans. " in cerr << .... Extra credit - short answer Why are you taking this class? How do you correctly spell my name?(teacher's name not yours!) What do you expect to get out of this class? Do you feel that this class is moving too slowly, too quickly, or just about right?
Scott Phipps 1) T/F Constant integers can only be changed when caled by reference. F, constant integers cannot be changed from their declared value. 2) T/F A basic C++ program that correctly displays a simeple message can be written using only the standard tempelate lilbrary. F, the iostream header file must be included in a program that takes input or gives output. 3) Which of the following C++ header files must be included to truncate a float number at three decimal places? A) number.h B) float.h C) none of the above C, iomanip.h must be included to manipulate the input/output stream. 4) T/F A variable name used in one member function of a class can be used in another member function to represent another variable. True. 5) Declare a two dimensional array with three rows and four columns where the rows contain the integers 1, 2, 3, and the columns contain the integers 4, 5, 6, 7. int array[3] [4] = {{1, 2, 3}, {4, 5, 6, 7}}; Poll: What is your favorite operating system or operating system varient (ie Redhat Linux, OpenBSD, Microsoft Windows 98, etc.)? Rajit Sharma 1) Multiple Choice: Vairable that contain the address of the starting point of a function are called: a)Constructors b)Function pointers c)Pointers d)String ans. Function Pointers True or False: 2)An array element is passed as a call-by-value argument to a function ans.true 3)Pointers are variables that contain memory location addresses as value ans.true 4)Find the error in the following code segment: x=1; while(x<=10); x++; } ans.The emicolon after the while header causes an infinite loop. 5)Name the program and state what it does: #include <iostream.h> #include <iomanip.h> int(main) { const int arraySize = 10; int a [arraySize ]={2,6,4,8,10,12,56,12,54,78}; int i, hold; cout<<"Data items in original order\n"; for (i=o;i < arraySize; i++) cou<< setw(4)<<a[i]; for ( int pass =0; pass , arraySize-1; pass++) for ( i = 0; i < arraySize -1; i++) if ( a[i] > a[i+1]) hold = a [i]; a[i] = a[i+1]; a[i+1] = hold; } cout<<"Data items in ascending order\n"; ans.Bubble Sort This program sorts an array's values in ascending order
Ryan Willhite 1. In a class, attributes are represented as a. functions b. objects c. data d.if statements correct answer is c 2. T/F A constructor is a class member function with a different name than the class. false (same name as the class) 3. 5! = 5*4! = 5*4*3*2*1 This function is an example of a. enumeration b. recursion c.function overloading d. exponentiation correct answer is b 4. T/F The following class definition has no syntax errors. class CSquare { private: int length; int width; public: CSquare(void); CSquare(const int &length, const int &width); } false (no semicolon at the end of the definition) 5. C is a procedural programming language while C++ is a(n) __________ language. a. sequential b. assembly c. encapsulation d. object-oriented correct answer is d Shobhit Sharma 1. Question on Assignment Statements. a user needs to assign a value 40 to hours. which of the following is the correct one: a. hours = 40; b. 40 = hours; c. hours == 40; d. 40 == hours; ans. a 2. if/else structure comes under which type of structures: a. Selection Structures b. Repetition Structures c. both of them d. none of the above ans. a 3. what does the Function Prototype Tells the compiler: a. The name of the function b. The type of data returned by the functions c. The number of parameters d. all of the above ans. d 4. Find the error in the following recursive function:
unsigned long factorial (unsigned long number) { if (number <= 1) return; else return number * factorial (number); } ans. return number * factorial (number-1); ( error in (number-1) ) 5. state true or false grade=45; cout << (grade > 60 ? "Passed" : "Failed"); output: passed ans. false Siddharth Khattar Here are my 5 questions. 1. What in C++ allows a programmer to create multiple functions with the same name? A: inline function B: default function C: function overloading D: recursion Ans : C. 2. Two classes cannot have data members with the same name True or False? Ans : False. 3 What must be true for the following statement to be valid: X=&Y; A X must be an integer B X must be a pointer C Y must contain an address. D Y must be an integer. Ans: B 4. Solve for X; Int x ,*z, y[10]= {12, 53, 8,97,23,87,34,75,40,66}; Int*A, *B; Z=y; A=&y[3]; B=&y[7]; 1: ________x= *z +5; ans: 17 2: ________x= B-A; ans: 4 3: ________x= A[3]; ans: 34 4: ________x= *A-*B; ans: 22
last question is equivalent to 4 questions. Tim Pierce 1. True or False The operator >> is called the insertion operator. false
2. What is the correct call to the function whose function prototype is
void printvalue (int x); A. y = printvalue(4); B. printvalue(4); C. printvalue(4.5); D. None of the above. Ans. B 3. Select the best name for this function. void f1 (int &x, int &y) { int temp = x; x = y; y = temp; } A. Sort B. Swap C. Print_value D. None of the above
Ans. B 4. The declaration of a global variable mus be placed _____. A. inside any function called by the main function B. inside the main function C. outside of any function D. none of the above Ans. C 5. Select the obvious reason why this ascending bubble sort algorithm does not work. grades[ARRAYSIZE] = {3, 6, 7, 4, 7, 8, 9, 5}; int temp; for (int pass = 0; pass < ARRAYSIZE - 1; pass++) for (int i = 0; i < ARRAYSIZE - 1; i++) { if (grades[i] > grades[i + 1]) { grades[i] = grades[i + 1]; grades[i + 1] = grades[i]; } }
A. The greater than sign should be a less than sign. B. There are too many braces. C. There is no temp variable used in the swap. D. None of the above. Ans. C Answers 1. False 2. B 3. B 4. C 5. C Vineet Khosla 1. true or false Can a class have more then one constructor? ans. true 2. what in c++ allows programmer to create multiple functions with the same name? a. inline function b. default arguements c. function overloading d. recursion function 3. find the 2 error in the following programme(bonus point if u can find 2 errors). int main() { const int x; x=7; return 0; } ans. a. constant variable "x" must be initialized b. u cannot modify a constant object. 4. look at the programme and tell which of the following staements is false. int f1(int[],int); int main() { int x[5],a,n; a=f1(x,n); return o; } a. function f1 cannot change the value of n b. function f1 can change the value of x. c. function f1 returns an integer. d. all the statements are true. 5. what is the name of the algorithm which compares each and every element of an array to every other element in order to sequence them. a. binary search b. linear search. c. bubble sort. d. bubble search. e. none of these. |