MCS2514: Computer Science 2
Lab Assignments and Answers
- Lab0 Answer: lab0.cpp (binary ftp) |
lab0.cpp (text ftp)
- Lab1 (Classes and Objects; Member functions and Non-member functions):
Complete lab1.cpp |
lab1ans.cpp
- Lab2: Answer
- Lab3: Answer
- Lab4
- Find bugs of this program: bagtst4lab.tst
and
modify "remove" member function using "while" instead of "for"
- Complete occurrences member function
- Expected Output
- Answer
- Lab5: Modify dynmbag.cpp to introduce
two overloaded operators for -= and -. This lab is similar to
Chap. 3 programming project #2 on page 136. A sample user dialog would look
like the following:
M:\cs2>lab5
Enter numbers, -1 when you are done: 1 2 3 4 -1
bag1: ( 1 2 3 4 )
Enter numbers, -1 when you are done: 1 4 5 -1
bag2: ( 1 4 5 )
bag1 - bag2 = ( 3 2 )
M:\cs2>
Answer
- Lab6 as well as Programming Contest #1:
SetTstQ.cpp,
SetTstQ.txt
- Lab7: Complete four functions (append, middle, max, and min)
in lab7.cpp. A sample output is
here. This lab is not for grading.
answer
- Lab8: Develop MyStack class publicly based on a
List class, listclass.h.
Complete and test lab8.cpp .
Ans
- Lab9: Testing Stacks and Queues, Self-Test Exercise 4 on page 384.
Use queue1.h and
stack1.h. Modify
pal.cpp.
[answer]
- Lab 10: Write recursive functions for the following problems, when a number "n" is
given by the user:
- to write out n stars(*)
- to write out n ... 1
- n factorial
- nth triangular number
- nth quadratic number
- sum of the squares of the numbers 1 through n
Sample outputs might look like this.
Copyright (C) 2000- by Chung