CSCI 201 – Computer Science 1Introduction to data abstractions.
Homework 9. Creating a class for the VEE figure
Due date: Saturday March 30
Objectives: Define a data abstraction, and implement and test it using C++ classes.
Using the code in Triangleclass in CourseFiles as an example, construct a class Vee, which represents the Vee-shaped figure that you created for the lab assignment in Week 5.
Question 1: designing the class. Answer each of the following questions before you start on
ant code:
(a) What data fields does the class need to define the appearance the Vee? What is the purpose of
each?
(b) We need two number fields for margins, so that the figure can be suitably positioned on the
screen/file. How will we keep track of these?
(c) Describe an appropriate format to read/write/store the data associated with the Vee objects.
(d) Separately list the private and public fields and the methods that are needed for this class.
Explain the header of each method.
Question 2: implementing the class . Write the complete code for the Vee class and compile
it separately.
Using the triangleTest program as an example, write a test program that tests all the features of
the Vee class. Make a script showing the compilation of the class, compilation of main, and tests.
What to submit Upload the answer to Question 1, script file from Question 2, and all code files
(.h, .cpp and the main) to the folder Homework 9 in your CourseFiles folder.
1
CSCI 201 – Computer Science 1
Lab 10: Creating a fraction class.
Due date: Tuesday April 2
Objective. Design and implement a class, that requires some mathematical operations, for a
library package.
Question 1. Creating a fraction class.
We have to design a class fraction, that can be used to read and write fractions in the format
a/b, and also check if two fractions are equal (Note that two fractions are equal if the product of
the first numerator and second denominator equals the product of the second numerator and first
denominator.)
(a) what data fields will the class have?
(b) what methods (member functions) will the class have? Write the header for each.
(c) create a UML diagram for the fraction class (see Section 13.15 in textbook).
Question 2. Write the code for fraction class.
Question 3. Write a program that tests all the features of the class. In a script session cat the .h,
.cpp files and the main program, compile the .cpp file for the fraction class using the -c option,
compile the main program with the object code (.o file), and run the program. Upload the script
file.
Extra Credit. Write a method simplify() that simplifies a fraction so that it is in the lowest
form, i.e., the numerator and denominator have no common factors. This will require computing
the Greatest Common Divisor (GCD). The strategy for finding the GCD of two positive integers,
a and b, (a > b), is as follows: if b divides a, exit and return b; otherwise continue with the new
a = old b, and new b = (old a) % (old b). This feature should be tested separately in a script
session, and uploaded to CourseFiles.
1