![]() |
CSC 215 |
|
Sample final questions |
Listed below are questions similar to those I will put on the final.
int equal(int a, int b, int c)that returns true if at least two of its parameters are equal and false otherwise.
int yearInCentury(int year)The parameter year contains a four-digit year. The function should return the number of the year in its century. For example, the year 1901 is the first year in the 20th century so the call yearInCentury(1901) would return 1. The year 2000 is the last year of the 20th century so the call yearInCentury(2000) would return 100.
int numberOfDigits(int n)that returns the number of decimal digits in the value in n. You may assume that this value is positive. For example, the call numberOfDigits(165) would return 3. (Hint: Note what happens when you divide the number by 10.)
void getMonthYear(int& month, int& year)that asks the user for a month and year and returns the values that are input in the month and year parameters. The function should not exit until the user has entered a month between 1 and 12 and a year between 1960 and 2000.
void exceeds(ifstream& inputfile, int limit, ofstream& outputfile)that reads the list of integers in inputfile and outputs to outputfile only those that are greater than or equal to the value in limit.
#include <iostream.h> void Fibonacci(int& first, int& second); int main() { int first, second; int index; first = 1; second = 1; cout << first << endl; cout << second << endl; for (index = 1; index <= 4; index++) { Fibonacci(first, second); cout << second << endl; } return 0; } void Fibonacci(int& first, int& second) { int temp; temp = second; second = first + second; first = temp; return; }