![]() |
CSC 215 |
|
Sample final solutions |
Listed below are the solutions to the questions I posted for the sample final questions.
int equal(int a, int b, int c)
{
if (a == b || a == c || b == c) {
return 1;
}
else {
return 0;
}
}
int yearInCentury(int year)
{
return ((year - 1) % 100) + 1;
}
int numberOfDigits(int n)
{
int digits = 0;
while (n > 0) {
n = n / 10;
digits++;
}
return digits;
}
void getMonthYear(int& month, int& year)
{
do {
cout << "Enter the month: ";
cin >> month;
} while (month < 1 || month > 12);
do {
cout << "Enter the year: ";
cin >> year;
} while (year < 1960 || year > 2000);
}
void exceeds(ifstream& inputfile, int limit, ofstream& outputfile)
{
int number;
while (inputfile >> number) {
if (number >= limit) {
outputfile << number;
}
}
}
1 1 2 3 5 8