Uploaded by toan pham duc

CS1 Final Study Guide

advertisement
CS1 Final Study Guide
1. Go over all examples from class and homework.
2. Know how to do the tracing problems with classes, aka BaskinRobbins type
problem.
3. What are some of the benefits to Object Oriented programming? What do the
concepts of object reusability and data hiding mean?
4. How do you access a data member of a structure/class?
5. How do you pass an array to a function?
6. Review functions from projects 3 and 4. Also review Pair Programming
assignments.
7. Understand this question?
if(score >= 90)
grade = 'A';
if(score >= 80)
grade = 'B';
if(score >= 70)
grade = 'C';
if(score >= 60)
grade = 'D';
else grade = ‘F’;
8. What is printed in the piece of code below?
int z=3, sum=0;
while(z<7)
{
z += 2;
sum=sum+z;
}
cout << sum;
9. Write code, using a loop, that produces the following output:
12 14 16 18 20
10. Consider the following expression: (A > B) && (C <= B)
Assume that A, B, and C are integer variables. Which of the expressions given
below is (are) equivalent to the one given above?
I. !(A < B) && !(C >= B)
II. (A > B) && (B > C)
III. !((A <= B) || (B < C))
Free Response:
1. Write a function, reverseString(string &str), that reverses the characters of
the string str, except ignore sections of numbers starting with a 6 and extending to
the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers.
string example = "Reverse";
reverseString(example),
cout << example; // prints out "esreveR"
2. Write the function repeatFront such that given a string and an int n, it returns a
string made of the first n characters of the string, followed by the first n-1 characters
of the string, and so on. You may assume that n is between 0 and the size of the
string, inclusive (i.e. n >= 0 and n <= str.size()). Hint: Solve this problem by using
C++ strings not C-strings.
Examples:
repeatFront("Chocolate",
repeatFront("Chocolate",
repeatFront("Ice Cream",
repeatFront("Ice Cream",
4)
3)
2)
0)
→
→
→
→
"ChocChoChC"
"ChoChC"
"IcI"
""
3. We are having a party with amounts of tea and candy. Return the int outcome of the
party encoded as 0=bad, 1=good, or 2=great. A party is good (1) if both tea and
candy are at least 5. However, if either tea or candy is at least double the amount of
the other one, the party is great (2). However, in all cases, if either tea or candy is
less than 5, the party is always bad (0).
teaParty(6, 8) → 1
teaParty(3, 8) → 0
teaParty(20, 6) → 2
Download