Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Final Exam Review for Computer Science I | COMP 128, Exams of Computer Science

Material Type: Exam; Class: COMPUTER SCIENCE I; Subject: Computer Science; University: Wentworth Institute of Technology; Term: Unknown 1989;

Typology: Exams

Pre 2010

Uploaded on 08/16/2009

koofers-user-mpa
koofers-user-mpa 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Comp128 Final Exam Review
1) Functions – Know how to set up function headers following a problem
specification, including return type and parameter lists. Know when to use the &
and when not to.
2) Decisions – Know how to use if and switch statements. You should be able to
convert from a nested if statement to a switch and vice versa. Know how to use
comparative operators such as ==, !=, <, etc. to do various tests, including testing
to see if a number is in a specified range. Know how to use the logical operators
&&, || and !.
3) Loops – Know the 3 basic loop constructs: while, do .. while and for. You should
be able to switch from one to the other.
4) Streams – Know how to use standard input and output, namely cin and cout.
Understand how to open a file and stream to/from it. Understand how to use
manipulators and stream flags to control the formatting of output.
5) Arrays – Know how to declare and initialize 1-D arrays. Be able to write
functions, which are passed arrays as parameters and need to do some processing
at each cell of the array. Understand how an array variable can also be thought of
as a pointer.
6) Strings – Know how to declare and use C-Strings, including use of functions in
the cstring library such as strcmp() strlen(),strcpy(). Understand how to use the
C++ string class.
7) Classes – Know how to declare a class including public and private member
variables and functions. Be able to implement member functions given their
specification. Know how to declare a variable whose type is a class, then use the
variable to invoke member functions.
8) Program Design – Know how to break down a large problem into smaller tasks
using top-down structured design techniques. Be able to draw a structure chart
showing functions as boxes, and using directed arrows to indicate parameter
passing. Also, know how to draw a simple class diagram, namely for each class a
rectangle divided into 3 compartments for the class name, member variables and
member functions.
9) Testing – be able to construct a driver function (usually main() ) to exercise
functions you have written and see if they are working correctly.
pf3
pf4

Partial preview of the text

Download Final Exam Review for Computer Science I | COMP 128 and more Exams Computer Science in PDF only on Docsity!

Comp128 Final Exam Review

1) Functions – Know how to set up function headers following a problem

specification, including return type and parameter lists. Know when to use the &

and when not to.

2) Decisions – Know how to use if and switch statements. You should be able to

convert from a nested if statement to a switch and vice versa. Know how to use

comparative operators such as ==, !=, <, etc. to do various tests, including testing

to see if a number is in a specified range. Know how to use the logical operators

&&, || and !.

3) Loops – Know the 3 basic loop constructs: while, do .. while and for. You should

be able to switch from one to the other.

4) Streams – Know how to use standard input and output, namely cin and cout.

Understand how to open a file and stream to/from it. Understand how to use

manipulators and stream flags to control the formatting of output.

5) Arrays – Know how to declare and initialize 1-D arrays. Be able to write

functions, which are passed arrays as parameters and need to do some processing

at each cell of the array. Understand how an array variable can also be thought of

as a pointer.

6) Strings – Know how to declare and use C-Strings, including use of functions in

the cstring library such as strcmp() strlen(),strcpy(). Understand how to use the

C++ string class.

7) Classes – Know how to declare a class including public and private member

variables and functions. Be able to implement member functions given their

specification. Know how to declare a variable whose type is a class, then use the

variable to invoke member functions.

8) Program Design – Know how to break down a large problem into smaller tasks

using top-down structured design techniques. Be able to draw a structure chart

showing functions as boxes, and using directed arrows to indicate parameter

passing. Also, know how to draw a simple class diagram, namely for each class a

rectangle divided into 3 compartments for the class name, member variables and

member functions.

9) Testing – be able to construct a driver function (usually main() ) to exercise

functions you have written and see if they are working correctly.

Sample Questions: For each of the function descriptions below:

a) Write the function definition code. b) Write a driver to test the function. It obtains test inputs from the user, calls the function sending necessary parameters, and then prints the answers.

  1. Write a function named smallest, which is passed an array of int, and its size, and returns the smallest int in the array.
  2. Write a function named total, which is passed an int n and returns the sum: 1 + 2 + 3 + …
    • n.
  3. Write a function named find, which is passed an array of char, its size, and a char, named target to look for. It returns the index value of the first cell which contains target, or –1 if target is not found in the array.
  4. Write a function named rotate, which is passed an array of int, and its size. It rotates the array by moving each int up 1, except for the last int, which is moved to the first position.
  5. Write a function named breakup. It is passed a whole number of inches, and breaks it up into yards, feet and inches. i.e. breakup(100) => 2 yards, 2 feet, 4 inches.
  6. Write a function named honor_roll. It is passed an array of test scores, and the size of the array. It returns the number of students who got A (90 – 100) and the number who got B (80 – 89).
  7. Write a function named circle, which is passed the radius of a circle and returns its circumference.
  8. Write a function named average, which is passed an array of double, and its size, and returns its average.
  9. Write a function named box, which is passed an int n, and prints out an n by n box made of asterisks.
  10. Write a function named hypotenuse, which is passed the two sides of a right triangle and returns the hypotenuse.
  11. Write a function named reverse, which is passed an array of char, and its size, and prints out the array in reverse order.
  12. Write a function named capitalize, which is passed a char, and returns a char. If the char passed is a lower case letter, it returns capitalized.
  13. Write a function named is_vowel, which is passed a char, and returns 1 if it is a vowel, 0, otherwise.
  14. Write a function count_vowels, which is passed an array of char, and its size, and returns the number of vowels in the array. You can use the function is_vowel to help.
  1. Consider the class definition below: class Date { private: int month; int day; int year; public: Date(void); //default constructor Date(int m, int d, int y);// initializing constructor void print(ostream & out);// prints date to ostream in //form mm/dd/yyyy ~Date(void); //destructor bool scan(istream & in);// scans a date in the form mm/dd/yyyy void setMonth(int m);// sets the month if it is valid int getMonth(void);// returns the month void euroPrint(ostream & out);// prints date in from dd-mmm-yyyy bool isValidDate(void); // returns true if the month,day,year //constitute a legal date bool isLeapYear(void); // returns true if year is a leap year- //i.e divisible by 4 and not by 100, or by 400 }; Write the implementations of all the functions. Be sure to include the class and scope resoulution operator. i.e. Date::Date(int m, int d, int y){.. }