midterm2-sampleSolutions_fall_2008

midterm2-sampleSolutions_fall_2008 - CS201 (Intro. to...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS201 (Intro. to Computing) MIDTERM II SAMPLE QUESTIONS – Fall 2008 Those questions do not imply any favorite subject or question type for the questions in the actual exam Please also review recitation questions, samples covered in the class, homeworks and the questions in the book as well The amount of questions here is of course much more than the actual exam. QUESTIONS 1) ) Write a program that solves the following problem: If April 23 rd of a year is a Sunday, what would be the day of week for October 29 th of the same year? Use date class! #include <iostream> #include <string> #include "date.h" using namespace std; void main() { int month=4,day=23,year=1900; //any year value would work bool check=true; while(check) { Date date1(month,day,year); if(date1.DayName()!="Sunday") { year++; } else check=false; } month=10; day=29; Date date2(month,day,year); cout << date2.DayName()<<endl; } © CS201 Team at Sabancı University
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2) a) Write a function that takes a date parameter and returns the number of days between that date and the last day of that month. int diffDay(Date thisDay) { return thisDay.DaysIn() - thisDay.Day(); } b) Write a function that takes a string parameter (call it str ) and returns true if the value of str is “Turkey”, returns false otherwise. All combinations of upper and lowercase letters in “Turkey” are acceptable. For example “TuRKey” or “TUrkeY” (among may other combinations) should also return true. bool IsTurkey(string str) { string turkey="turkey"; ToLower(str); if(str==turkey) return true; else return false; } c) Consider the following loop int sum = 0; RandGen r; for (int a=1; a<=20; a++) { sum+=r.RandInt(1,a); } What can you say about the value of sum after this loop? Sum is an integer number in the [20 . . 210] range. d) What is the output of the following program piece? (December 10, 2002 was a Tuesday) Date day(12,10,2002); Date horrorday = day + 3; string s=horrorday.DayName(); cout << horrorday << " " << s; December 13 2002 Friday © CS201 Team at Sabancı University
Background image of page 2
3) Write a function that takes a real number as parameter and returns its fractional part. For example, if the parameter is 145.943422, the function should return 0.943422. As another example, if the parameter is -2.4, the function should return 0.4. Write a program that inputs 10 real numbers from keyboard and finds out the real number with the largest fractional part. Your program should display this number. Program should use the above function. Moreover your program should check if the input numbers are real number or not. If a particular input is not a real number, it should be re-entered by the user until a real number is entered. 10 is the number of real numbers! #include <iostream>
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/16/2012 for the course FENS 101 taught by Professor Selçukerdem during the Fall '12 term at Sabancı University.

Page1 / 18

midterm2-sampleSolutions_fall_2008 - CS201 (Intro. to...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online