We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2
Function
1. Write a function named mult() that accepts two floating-point numbers as a
parameters, multiplies these two numbers and display the result. 2. Write a function that accepts a year as a user input and returns a one if the year is a leap year or a zero if it is not. 3. Write a program that can be used to play a number guessing game. The player is first asked for the number of games he wishes to play. Each game gives the player a maximum of three chances to guess a number chosen randomly. If the player makes a correct guess, he is given a score depending on the number of guesses he has made (10, 8, or 5). The final score is given as a percentage with some complementary remarks. 4. Consider the following program: int foo(int x) { static int k = x; if (x == 0) return 0; if (x < 0) return k + foo(-x); else { int y = foo(x-1); return k + y + 1; } } What will this program compute? 5. Consider the following code fragment # include <iostream.h> char key; int o,p; long int number; float q; int main() … { return p; int a,b,c; } double x,y; double func2( float fisrt, float last) … { return 0; int a,b,c,o,p; } floar r; double secnum; double s,t,x; int func1(int num1, int num2) … { return s*t; } Draw a box around the appropriate section of the above code to enclose the scope of the variables key, secnum, y, and r. 6. Describe the difference between a local auto variable and a local static variable. 7. Given the following code: int sum(int 0) { if(n==0) return 0; else return(n+sum(n-1)); } a) show the terminating condition b) show the recursive part c) hand trace this peace of code for n=4 and find the output. 8. Write a recursive program that a. Checks whether a given word is palindrome. A word is plaindrom if it has same spelling when we read it from left to right and vice versa (e.g noon) b. Checks whether two one dimensional arrays of the same size are identical (have the same elements) 9. Determine the values displayed by each cout statement in the following program: #include <iostream.h> int firstnum=20; void display(void); int main() { int firstnum =20; cout<<”\nthe value of firstnum is<<firstnum<<endl; display(); return 0; } void display(void) { cout<<”the value of firstnum is now<<endl; return; } 10. Write a modular program that reads a list of marks and display their range, mean, median. Suggested functions and their prototypes: Void readList(float myList[], unsigned & maxNo); Float findMax(const float myList [] , unsigned maxNo); Float findMin(const float myList [] , unsigned maxNo); Float findRange(const float myList [] , unsigned maxNo); Float findmean(const float myList [] , unsigned num); Void display(const float myList [] , unsigned maxNo);