SAMPLE QUESTIONS FROM CIS67 EXAMS (G.Ingargiola (Thanks to the people from whom I copied many of these questions) ============================================================================== A Computer System includes Hardware, Software and People. List some of each and what they are/do. ============================================================================== What are the basic components of a computer? ============================================================================== What are milliseconds? microseconds? nanoseconds? ============================================================================== What are Kilobytes? Megabytes? Gigabytes? Terabytes? ============================================================================== Describe what is meant by "Compilation" and "Compiler". ============================================================================== What is a BIT? what is a BYTE? ============================================================================== What are current values for the capacity and acces time of a hard disk? ============================================================================== What are current values for the capacity and access time of main memory? ============================================================================== The performance of a Central processing unit is at times described in terms of Megahertz, or of MIPS, or of MFLOPS. What are they? ============================================================================== What is 2 raised to the 9th? how many different patterns of 0s and 1s can you have in a byte? ============================================================================== Describe in detail the steps involved in going from a problem statement (for example, the statement of a homework), to the moment that you have a corresponding running program in C. ============================================================================== It is recommended that you adopt the following steps when solving a programming problem: Problem Statement Analysis Design Implementation Testing Say what is meant by each step and give an example, say, from one of the homeworks. ============================================================================== Describe function stubs and how we can use them in the top-down development of a program. ============================================================================== Describe function drivers and how we can use them in the bottom-up development of programs. ============================================================================== How do we use the assert function during the development, testing, and use of software? ============================================================================== What is the purpose of testing? how do you choose the test data? ============================================================================== Explain briefly a topic that you have understood well in this course. ============================================================================== Describe a topic that you have understood poorly in this course and explain why you think it so happened. ============================================================================== Describe briefly typical bugs that you made in your programs. ============================================================================== ============================================================================== What is done by the following Unix commands? 1. rm lab1.cpp 2. cd lab3 3. ls ============================================================================== Specify 3 Unix commands you have used and say what they do. ============================================================================== Name some of the tools/programs that you use when developing your own programs ============================================================================== ============================================================================== a. What is an identifier? Give two examples. b. What is a keyword? Give two examples. c. What is the size of an int on the computer we use in the lab? d. List the data types we have used. e. What is printed out by "cout << 7 < 11 << endl;" ============================================================================== What is printed out by "cout << 3 < 4 << endl;" ============================================================================== Give an example of: (a) A compiler directive (b) A variable declaration (c) A Conditional Statement (d) A loop Statement (e) An I/O Statement ============================================================================== What is a variable in C++? Give at least one example and show how variables are used. ============================================================================== What is a data type? Give at least one example. ============================================================================== What is the Scope of an identifier? ============================================================================== What is the difference between a Declaration and a Definition. ============================================================================== Describe the Break Statement and the Continue Statement. Be sure to indicate where they can be used and what they do. ============================================================================== A unique and unusual data value that is placed after all actual data is called a a. terminal value b. sentinel value c. loop-control variable d. input value e. loop termination variable ============================================================================== For a function, what are: (1) its formal parameters (2) an actual parameters (3) rules for correspondence of formal and actual parameters. ============================================================================== Consider the C++ statement: cout << "Enter the file name: "; (1) What does cout represent? (2) What kind of basic C++ token is "Enter the file name: " ? (3) What kind of basic token is << ? (4) What kind of basic token is ; ? ============================================================================== Give examples of each of the three possible methods for passing parameters to a function. ============================================================================== Explain what are the three possible modes for formal parameters of a function. ============================================================================== What is a string? Give the definition, a declaration of a string variable, an example of a string literal. ============================================================================== Describe as many operations on strings as you can remember. ============================================================================== What is a c-string? Give the definition, a declaration of a c-string variable, an example of a c-string literal. ============================================================================== The following is said about parameters of C++ functions: Parameters can be passed by value, or by address, or by reference. Indicate what this means and give an example of a parameter passed by value, of a parameter passed by address, and a parameter passed by reference. ============================================================================== Give one example for each of the following kinds of loops: (a) Counting Loop (b) Sentinel Loop (c) Conditional Loop (d) General Loop ============================================================================== For each of the three possible loop statements while, for, do-while specify the minimum and maximum number of iterations that may take place. ============================================================================== What function call type is used when the symbol '&' immediately follows an argument in a function header? ============================================================================== Once a function is defined in a program, how many times can it be called within the main function? ============================================================================== What is integer overflow? What are the advantages and disadvantages of using a float representation? ============================================================================== What is a string? Give the definition, a declaration of a string variable, an example of a string literal. ============================================================================== Describe as many operations on strings as you can remember. ============================================================================== Debugging is a term that refers to: (a) A technique for writing programs (b) A technique for eliminating errors in programs (c) A technique for finding out if a program has errors (d) The activity of eliminating known errors from a program ============================================================================== Testing is a term that refers to: (a) A technique for documenting a program (b) The activity that finds out if a program has errors (c) A technique for producing more elegant output (d) A technique for improving the efficiency of a program. ============================================================================== Coding is a term that refers to: (a) What we do when we write a program (b) What we do when we enter the data of a program (c) A technique for eliminating the errors from a program ============================================================================== Design is a term that refers to: (a) A technique for writing programs (b) The activity of planning the implementation of a program (c) A technique for finding out if a program has errors (d) The specification of the purpose of a program ============================================================================== Describe in English the Linear Search Algorithm and give its function prototype for integer values ============================================================================== Write the function linear that, given an array a with n strings, and a string b, returns either the position in a where b occurs, or -1 if not there. ============================================================================== Describe in English the Binary Search Algorithm, give its function prototype for integer values, and indicate its complexity in terms of the number n of given values. ============================================================================== Implement the function int getFrequency(const string a[], int n, const string& name); which, given an array a with n elements and a string name, it returns the number of occurrences of name in a. ============================================================================== Implement the function morph that, given a strings s capitalizes each letter and replaces each occurrence of "PH" by "F" and each occurrence of "CH" by "K" and returns the total number of replacements made int morph(string& s) ============================================================================== Describe in English the Bubble Sort Algorithm and give its function prototype for integer values ============================================================================== Describe in English the Merge Algorithm and give its function prototype for integer values ============================================================================== We have said that the computational complexity of Bubble Sort is n*n, where n is the number of elements being sorted. What does it mean? Do you remember how we reached this conclusion? ============================================================================== Here is the code for insertion sort: void insertionSort(int a[], int n) { for (int limit=1; limit < n; ++ limit) { int v=a[limit]; int k=limit-1; for (; k>=0 && a[k]>v; -k) a[k+1] = a[k]; a[k+1] = v;}} Write precisely the invariant of each loop. ============================================================================== For the binary search function: int binary(const int a[], int n, int who) { int low(0); high(n); while (low <= high) { int middle = (low+high)/2; if (who <= a[middle]) high = middle else low = middle + 1; } if (who == a[low]) return low; else return -1; } Write (a) The precondition for this function (b) The postcondition for this function (c) The loop invariant of the while loop. ============================================================================== ============================================================================== Mark all the words that are not legal identifiers: Anna sam Joe's house#7 r2p2 ============================================================================== Consider the following loop statements: (a) while (E) S; (b) do S while (E); (c) for (lcv=0;lcv<4;lcv++)S; where E is a boolean expression and S is some executable statement. What is the minimum number of times that S will be executed in the three case? what the maximum? ============================================================================== Show the output of the following for loop: for(i=0;i<6;i++) cout << i; ============================================================================== What is printed out by the following program fragment int x = 9; while (x > 3); { cout << x << endl; x--; } ============================================================================== What is written by the following program fragment: for (int k=0; k < 5; k += 1) { for (int j=0; j0) if(y>0) z=2; else z=3; cout << "z = " << z; ============================================================================== Assuming the declarations: int y(4); int z(3); what is printed out by: cout << (9 + y / z >= 7 || y == 5 && z%2 == 0)?7:11; Explain your answer. ============================================================================== Given the variables int x, *y; int& z; complete the input statement below to initialize the variables x, y, z: ??? cin >> x >> ????? ============================================================================== Describe all that you know about the following function prototype: int moo (char *a[], int n); [of course you do not know what MOO does, but you know what it is, what are its parameters..] ============================================================================== What is printed by the following program fragment (explain your answer) int x; cin >> x; if (x) cout >> "Roses\n"; else cout >> "Violets\n"; ============================================================================== What is printed by the following program fragment: for (int k=0; k < 6; k += 1) { for (int j=0; j<3*k; j++) cout << ' '; cout << 'X' << endl; } ============================================================================== What is printed by the following program fragment: .... { int lcv; int a[7]; for (lcv=0;lcv<7;lcv++) a[lcv] = lcv + 2; for (lcv = 6;lcv>=0;lcv--) cout << a[lcv] << "\T"; cout << endl; ..................... } ============================================================================== What is printed by the following program fragment: ....... { int lcv; char a[] = "9876543210"; for (lcv=0;lcv>3;lcv++) cout << a[lcv]; ....... } ============================================================================== What is printed out by the following program fragment: for (int i = 1; i <= 9; i++) if (i % 3 == 0) cout << char(int('A') + i); else cout << 'A'; endl; ============================================================================== What is the output of the following program fragment: for (int lcv=7853; lcv>=0; lcv /= 2) cout << (lcv % 2) << endl; EXTRA POINTS If you identify the meaning of what is being done. ============================================================================== What is printed out by the following program fragment: int main(){ char a[3][6] = {"roses", "are", "red"}; for (int k=0; k<3; k++) cout << a[k][k] << endl; } ============================================================================== What is printed by the following program? #include using namespace std; int x = 2; int y = 3; int z = 4; void moo(int x, int *y){ int z; x = x+3; *y = *y+3; z = z+3; cout << "moo: x= " << x << ", y= " << y << ", z= " << z << endl; } void main(void){ moo(x, &y); cout << "main: x= " << x << ", y= " << y << ", z << endl; } ============================================================================== Given the following program fragment int s = 1; int t; for (cin >> t; t != 0; cin >> t) s *= t; a. The value stored in variable s at the end of the execution of the loop could best be described as ____________________________. b. Rewrite the loop using a while statement. ============================================================================== Given the function definition: void moo(int x, int *y, int& z) { x = *y + z; *y = *y - 7; z = x * (*y); } (a) How is each parameters passed? (b) What is the mode of the parameters? (c) What is the output of the program fragment: int a=2, b=3, c=4; moo(a, &b, c); cout << a << " " << b << " " << c << endl; ============================================================================== Given the function prototype: void moo(int x, int *y); 1) How is the parameter x passed? 2) How is the parameter z passed? 3) How would you call this function using integer variables a and b as actual parameters? ============================================================================== What is the output of the following program fragment: for (int lcv = 1; lcv<=5; lcv++){ cout << lcv << endl; lcv = lcv + 2; } ============================================================================== What is the output of the following program fragment: { int a[10]; int lcv; for (lcv=0;lcv<10;lcv++) a [lcv] = lcv; for (lcv=0;lcv<5;lcv++) cout << a[lcv] << " " << a[9 - lcv]; } ============================================================================== What is the output of the following program fragment: cout << 20/3 << endl; cout << 10%3 << endl; cout << ((double)20)/3 << endl; cout << (int)3.1416; ============================================================================== Write a function that, given an integer X, returns 1 if and only if X is a multiple of 13, otherwise returns 0. ============================================================================== Write the function root that given three numbers a,b,c returns the value (you can use a standard function to compute the square root) --------- -b + \/b*b - 4ac ---------------- 2a ============================================================================== Given an integer array A and a double array X (both A and X have 12 components), print their elements as follows A[0] X[0] A[1] X[1] ............... A[11] X[11] using 9 columns, right aligned for the integers, and 12 columns, with two to the right of the decimal point for the reals (use scientific notation and be sure that, if one of the reals is a whole number, say 8, it is printed out as a 8.00) ============================================================================== Without worrying about declarations and initialization of variables, what errors do you find in the following program fragment: if x > 2 x++; else if x < 30 x = x + 12; cout << x; else x = 0; ============================================================================== Implement the function: void printfactors (int n); {prints out all the integers, greater than 1, that evenly} {divide the positive integer n} ============================================================================== Write a program that reads two integers from the input and prints out all their common factors (i.e. if the numbers entered are 6 and 15, then the output is 1, 2, 3). ============================================================================== Implement the function // It returns 1 if and only if all the values // in the array a with m rows and 7 columns // are non zero. int isAllOnes(int a[][7], int m) ============================================================================== Implement the function sum_them_up that, given an array with n elements, where each element is an integer array with 7 elements, returns the sum of all these integers. ============================================================================== Assuming that the integer variable x has value 3, what is its value after each of the following statements: (a) x++; (b) x *= 5; (c) x = (x<2)?7:9; (d) x = x%2; ============================================================================== Write in C++ the following expressions: (a) The character variable c is equal to a lower y or to an uppercase Y (b) The character variable c is a capital letter (c) The integer variable x is greater than 6 or it is less that 3 ============================================================================== Write the prototype of a function moo that takes as arguments a string and an integer and returns no value. ============================================================================== Implement the function replace_all that, given strings s1, s2, s3 replaces all occurrences of s2 in s1 by s3 and returns the number of replacements made. int replace_all(string& s1, const string s2, const string s3) ============================================================================== Write in English the meaning of the following declarations (a) int *x; (b) char y[7]; (c) int *f(char x[], int n); (d) int x[2][3]; (e) int *x[3][4]; (f) int foo(int x, char *who); (g) int *foo(int a[], int n); (h) void *foo(int a[], int n); (i) char moo(void); (j) const char * const a[]; ============================================================================== Assuming that the integer variable n contain 5, what is printed out by the program fragment: int *a = new int[n]; for (int k=0; k> mystery; for (int i = 0; i < 100; i++){ scores[i] = 100 - i; if (scores[i] == mystery) index = i; } cout << index << endl; //what does thid code do? ============================================================================== int i, scores[10]; for (i = 0; i < 9; i++) scores[i] = 9 - i; for (int i = 0; i < 10; i++) scores[i] = scores[9 - i]; // What values are in the scores array? ============================================================================== Trace the values taken by the variables product and i in the following code fragment: int product = 1; for (int i = 1; i <= 5; i++) product *= i; ============================================================================== //Reads data from stream ins into the array x with size elements //and returns the count of values stored in x. int readData(ifstream& ins, int x[], int size){ int i = 0; while (i < size && !ins.eof()){ cin >> x[i]; i++; } return __; //Fill in the correct expression } //Trace this on a data stream consisting of the even number from 2 to 10 ============================================================================== Implement the function addSubtract(int a, int b, int *c, int *d); which returns in c the sum of a and b and in d the difference of a and b. ============================================================================== Implement the function void shift(int a[], int n, int k); that given an array a with n elements and an integer j, 0> ins >> ins >> } 2) Write a function to display on the screen a struct variable passed as its input argument, void writePerson( ) { cout << "Name: " << cout << "Age: " << } 3) Write a function that increases the age component of its struct argument: ============================================================================== For the Selection sort algorithm for each array subscript i from 0 to n-2 1. Find the position of the smallest value in the subarray with subscripts i through n-1. 2. Exchange the smallest value with the value at position i. trace the action of the algorithm on the array below by filling in the array contents at the end of each loop repetition or "pass through the array". Draw a box around the part of the array that is sorted on each line. How does the sorted part of the array change at the end of each pass? 35 20 15 30 25 40 10 initial array 10 20 15 30 25 40 35 at end of pass 1 at end of pass 2 at end of pass 3 at end of pass 4 at end of pass 5 at end of pass 6 For a 7 element array, there will be 6 comparisons during the first pass and at most 1 exchange of values. Write down the number of comparison for an n-element array as a mathematical series. ____ + ____ + ____ + ... What would be the number of exchanges? Can you make a small change to the algorithm that reduces the number of exchanges? ============================================================================== For the Insertion sort algorithm: for each array subscript i from 1 to n-1 Store the value with subscript i in nextVal. For the subarray with subscripts 0 through i-1 move all values larger than nextVal one position to the right, making sure you start with the value at subscript i-1. Store nextVal in the last array element whose value was moved. trace the action of the algorithm on the array below by filling in the array contents at the end of each loop repetition or "pass through the array". Draw a box around the part of the array that is sorted on each line. How does the sorted part of the array change at the end of each pass? 35 20 15 30 25 40 10 Initial array 20 35 15 30 25 40 10 after inserting 20 after inserting 15 after inserting 30 after inserting 25 after inserting 40 after inserting 10 write down the number of comparisons and moves during each insertion. ____ + ____ + ____ + What would be the maximum number of comparisons and moves? Under what circumstances would this happen? What would be the minimum number of comparisons and moves? Under what circumstances would this happen? ============================================================================== You are given an integer array A with the following values {5, 2, 6, 1, 3, 4}. Show the content of A as it is sorted using Insertion Sort. ============================================================================== As a function of the number n of elements in an array, how many operations are done when: a. we sort the array using insertionsort b. we carry out a linear search on the array c. we carry out a binary search on the array Explain your answer in at least one case. ============================================================================== Identify the error in the code segment: void main(){ int x[8]; for (int i = 0; i < 9; i++) x[i] = i; } ============================================================================== Identify the error in the code segment: enum day (sunday,monday,tuesday,wednesday,thursday,friday,saturday}; day today; float week[today]; ============================================================================== What is printed out by the following program fragment? enum color {red, green, blue=5, white, yellow=15}; cout << red << green << blue << white << yellow << endl; ============================================================================== Given the arrays: int scores[10], happy[20]; Show the values of the first and last elements of the array scores and happy after the loop below executes: for (int i = 0; i<10; i++){ scores[i] = i*i; happy[i+10] = scores[i];} ============================================================================== You have a function named switchArray with the following description and prototype: // Exchanges the values stored in its two array arguments void switchArray (int a1[], int a2[]); What additional argument(s) does function switchArray need to do its job? ============================================================================== Assuming the declarations below: struct person { string name; int dependents; int age; }; person me, you; int babies; 1) Write a statement that increases the dependents field of me by 1. 2) (true/false) The statement you = me; copies all data in variable me to you. 3) The conditin (you == me) is true if corresponding fields of variables me and you contain the same data. 4) Write a function isOlder that returns true if the person represented by its first argument is older than the person represented by its second argument. 5) Write a loop that changes the data in the name field of me to all uppercase letters. 6) Write a statement that increases the dependents field of you by the value of babies. ============================================================================== Declare a struct type group_s with an array field persons that can store up to 100 objects of type person. The struct type group_s should also have an integer field that represents the actual size of the array (the number of person objects currently stored). Assuming a variable myClass of type group_s, write statements to increment by 1 the age field of every person in myClass whose name field has the same value as yourName (a string variable) ============================================================================== Correct the errors in the following switch statement. Also, modify it so that it works for uppercase letters too. gender is a character variable. switch (gender) { case 'f' : cout << "Hello, Ms. " << "Jones" << endl; case 'm' : cout << "Hello, Mr. " << "Jones" << endl; default : cout << "Invalid value for gender." << endl; } ============================================================================== For what exact range of values of variable x does the following code segment print 'C'? if (x <= 200) if (x < 100) if (x <= 0) cout << 'A'; else cout << 'B'; else cout << 'C'; else cout << 'D'; ============================================================================== For what exact range of values of variable x does the following code segment print 'C'? When does it print 'B'? if (x >= 200 && x <= 300) cout << 'A'; else if (x >= 100) cout << 'B'; else if (x >= 0) cout << 'D'; else cout << 'C'; ============================================================================== In the following expression, which operator will be evaluated first and which will be evaluated last? If y (type int) is 5, and z (type int) is -2, what is its value? 9 + y / z >= 7 && y == 5 ============================================================================== Given the following program fragment: int z, g, s, i, t; z = 0; g = 0; s = 0; i = 0; while (i < 50){ cin >> t; s += t; if (t >= 0) g++; else z++; i++; } 1) How many times is the loop body executed? 2) The value stored in variable s at the end of the execution of the loopcould best be described as a. average of the numbers read b. largest of all numbers read c. sum of all numbers read d. number of numbers read e. sentinel value terminating the loop 3) The value stored in variable z at the end of the execution of the loop could best be described as a. number of positive items read b. sum of all positive items read c. number of negative items read d. sum of all negative items read e. sentinel value terminating the loop. 4) The loop can best be categorized as a. counter-controlled loop b. sentinel-controlled loop c. general conditional loop d. do-while loop e. none of the above. ============================================================================== What does this program segment do? int s, i, n; s = 0; for (i=n; i>=1; i--) if ((i % 2) == 0) s += i; a. Adds all the integers from 1 to n b. Adds all the integers from 1 to n-1 c. Adds the even integers from n down to 1 d. Adds the odd integers from 1 to n e. None of the above. ============================================================================== Rewrite the code segment below using a while loop to produce a code segment that is exactly equivalent: product = 1.0; for (int i = 1; i <= m; i++) product *= i; ============================================================================== Show the output of the following program for (int k = 0; k < 5; k++){ for (int i = 0; i <= k; i++) cout << '.'; for (int j = 0; j < 2*k-1; j++) cout << 'B'; cout << endl; } ============================================================================== Given the function prototype: float computeAve(int, int, int); 1) the function call x = computeAve(x, 5, 12); is valid if x is type int or type float TRUE | FALSE 2) the prototype indicates the function has _____ input arguments and returns ______________. 3) Indicate all the errors in the following definition of computeAve: float computeAve(int x1, x2, x3) { return (x1+x2+x3)/3; } ============================================================================== What is the output from the following program? #include void doSomething(int thus, int that){ int theOther; theOther = 7*that; thus = 5*theOther; that++; cout << thus << that; } void main(){ int a, b; a = 1; b = 2; doSomething(b, a); cout << a << b; } ============================================================================== The ASCII code assigns increasing numeric values to the uppercase letters (i.e. 'A' is 67, 'B' is 68, and so on). Therefore the value of the expression int('F') - int('A') is ____ ============================================================================== In evaluating the following logical expression, which are the first and last operations to be performed? (Assume that all operations are eventually carried out.) c == a + b || a < b - d ============================================================================== What is the complement of the following expression n || a <= b && c != 100 ============================================================================== Given the program fragment: char r, x, y, z, w; cin >> x >> y >> z >> w; if (x> ctl; switch (ctl){ case 0: case 1: cout << "red"; case 2: cout << "blue"; case 3: cout << "green"; case 4: cout << "yellow"; } cout << endl; ============================================================================== Write a function called min that has two integer input arguments and returns the smallest of its two arguments. Don't use any library function to do this. ============================================================================== Implement the function double avg(int a, int b); which returns the average of the numbers a, a+1, a+2, ... , b ============================================================================== Implement the function fileSize that, // Given the name of a file, filename, // it returns the number of characters // in that file. int fileSize(char *filename); ============================================================================== Write a function called min3 that has three integer input arguments and returns the smallest of its three arguments. Write this function without using an if statement. ============================================================================== Write the data requirements and algorithms for a program that reads a collection of positive integer values ending with an appropriate sentinel value. Your program should find and display the smallest value, the average value, and the number of items in the collection. ============================================================================== Given the following program fragment: int sum(int a, int b){ return (a+b); } void main(){ int a=1, b, c; b = sum(a, a); c = sum(sum(a,a), sum(a,a)); } 1) What is the value of b? 2) What is the value of c? 3) Is the following statement correct? why? sum(a,a) = b; ============================================================================== Given the following (incorrect) function: int factorial (int n){ if (n <= 1) return 0; else return n*factorial(n-1); } 1) What should be changed in the above function for it to correctly return the factorial of a positive integer? 2) What would happen during the execution of the corrected function (i.e. the function obtained after the changes in 1.) if the expression n*factorial(n-1) were replaced by n*factorial(n)? 3) Would the corrected function (i.e. the function obtained after the changes in 1.) return a different value if the argument n is passed by reference? ============================================================================== Given the following program fragment: #define KAPPA = 5.66 const float PI = 3.14159; int a = pi + 1; 1) Is there any syntax error in the statements above? if yes, what is it? 2) Would the following statement generate an error message if it was added to the end of the program segment? Why? PI = PI + 2.3; 3) What is the value of a? ============================================================================== Given the following program fragment: char b, c, d, a = 'B'; b = --a; c = ++a; d = a/10000; 1) What is the character stored in b? 2) What is the character stored in c? 3) What is the value of d? ============================================================================== Given the following program segment: ofstream f_number1; ifstream f_number2; f_number1.open("number1.txt"); if (f_number1.fail()){ cout << "Error - cannot open file 'number1.txt'\n"; return 0; } 1) What is f_number1? 2) What is f_number2? 3) What would f_number1.fail() return if the file number1.txt could not be open? 4) What object class does the function f_number1.fail() belong to? ============================================================================== Given the following program fragment: void dummy(char& a, char b, int& c){ toupper(a); toupper(b); if (isdigit(b)) c = int(b) - int('0'); else if (isalpha(b)) c = int(b) - int('A'); else c = 99; } void main(){ char aa, bb; int cc; aa= '5'; bb='z'; dummy(aa, bb, cc); cout << aa << bb << cc << endl; } 1) What libraries need to be included? 2) Indicate the kind (input, output, input/output) of each formal parameter. 3) Trace the function calls and indicate what is displayed when the program is executed. ============================================================================== Given the structure struct moo { int x; int y;}; implement the function void init_moo(moo *a[], int n, int m) which given an array a with n pointers to moo structures, initializes all the fields of these structures to m. ============================================================================== Write a program that reads a string and two integers from the keyboard and writes the factorials of the two integers into the external file "facts.txt". You should write the string left justified in columns 1-10, the first factorial right justified in columns 11-20, and the second factorial right justified in columns 21-30. ============================================================================== Write a function int sumAvg(char *filename, int& sum, double& avg) which, given the name of a file that contains integers, reads all those integers and stores in sum their sum and in avg their average. The function returns 1 if it failed to open the file. Otherwise it returns 0. ============================================================================== Implement the function int count_chars(const char *filename) which, given the name of a file, returns the number of characters in that file. It returns -1 if it cannot open the file. ============================================================================== Write your own version of the function isdigit. ============================================================================== Write your own version of the function strlen that given a C string returns its length. ============================================================================== Implement the function my_strcat that, given two c-strings s1 and s2, concatenates s2 at the end of s1. void my_strcat(char *s1, char *s2) ============================================================================== Write a function get_in_range with 2 integer arguments, a and b, that prompts the user to enter a value in the range between a and b and that returns the first data value read that is between a and b, inclusive. ============================================================================== Write a function moo that, given a string s, returns a copy of s where each occurrence of 'a' or of 'A' has been replaced by 'Z'. ============================================================================== Write a program that, given on its command line two names, say, "john" and "smith", prints them out on a line. ============================================================================== Write a function moo that, given a string "filename" representing the name of a file, an array "table" of integers, and an integer "n" specifying the size of the table, writes to the file the content of the table. ============================================================================== Implement the function int count_lines(const string &filename) which, given the name of a file, returns the number of lines in that file. It returns -1 if it cannot open the file. ============================================================================== Explain how you can read the content of a file student.dat containing information about students (name, midterm, final, and homework. ============================================================================== Explain how you can write to a file students.dat from your C++ program. ============================================================================== Given the structure struct person { char name[30]; int income; }; and the function declarations: void moo1(person a); void moo2(person *a); void moo3(person &a); indicate for each of the three functions: (a) How a is passed (b) What is the mode of a (d) The assignment statement that sets within the function the income of a to 10. ============================================================================== Say in english the following declaration: int moo(const int *a[], int n); ============================================================================== Here is a simple class definition: class entry { public: entry(); void set_entry(const string&, const string& nr = ""); string get_name() const; string get_number() const; private: string name; string number; }; Explain: 1) What are the various elements of this definition. 2) How could you use this definition. ============================================================================== Using the class Entry defined in the previous question implement the function: // It writes to the file with name filename the // name and number of the entries in the first n // positions of the array e. It returns -1 if it // fails to open the file, 0 otherwise. int writeEntries(const char *filename, const Entry e[], int n) ============================================================================== Given the type: struct node { node * next; int val; }; and the variable node *x; write the C++ statements that will create the following data structure: +---+ +---+ +---+ x -->| |--->| |--->| / | +---+ +---+ +---+ | 4 | | 7 | | 5 | +---+ +---+ +---+ ============================================================================== Given the following recursive function definition void moo (int n){ if (n != 0) { cout << n%10; moo(n/10); } } Show what is printed out by the call moo(237) and explain what the function does in the general case. ============================================================================== Given the following recursive function definition int moo(int x, int n){ if (n > 0) { return x * moo(x, n-1); else return 1; } Show what is returned by the call moo(4, 3) and explain what the function does in the general case. ============================================================================== Given the following recursive function definition void moo (int a[], int n){ if (n > 0) { cout << a[n-1] << endl; moo(a, n-1); } } Show what is printed out by the call moo(b, 4), where b is declared by int b[] = {7, 2, 3, 4}; and explain what the function does in the general case. ============================================================================== Given the following recursive function definition int moo(int x){ if (x == 0) return 0; else if (x%10 < 5) return (1+moo(x/10); else return moo(x/10); } Show what is returned by the call moo(48153) and explain what the function does in the general case. ============================================================================== Given the structure struct person { string name; int income; }; and the declaration person *committee[3]; (a) Say in english what is the effect of the statements for (int k=0; k<3; k++) committee[k] = new person; (b) Assuming that committee has been allocated as indicated in (a), how do you set the income of all persons in the committee to 10? ============================================================================== Declare a data structure you might use to store in memory the names of all your friends. ============================================================================== Declare a data structure you might use to store in memory the name, age, weight, and height (in inches) of your best friend. ============================================================================== Define a class person with the private data members string name; int income; and the methods (at least two constructors and an accessor to name)and operators (at least '<<' and '+' for adding to the income) that you find appropriate. ==============================================================================