LAB 1:  Due 11:59 pm, Mon Sep 4

Submit the link to your project to Moodle before the deadline. Do Not modify after the deadline.


Background

This assignment is a review from the first programming course

This program with be done with pair programming. You will be assigned a partner.

First review the following Point class used to store information for points on a plane:

Point Class

Here is code for the Point class, along with a test driver: Link

Review this code, this is a model for both the design, coding and testing a class. This code used operator overloading, something you learn in introduced in programming, but it also overloads the built in binary operators == and – (which may be new to you. Play with this code, and make certain you understand it.

Problem 1: Roman Numerals.

(Based on textbox chapter 1 programming problem 1) Here is the repl link for this project: roman numerals. Here are algorithms for conversion: link. The class will internally store the number in string. You must design the class for roman numerals so that it follows this design:

romanType Class

You should also write private helper functions to convert from a int to a roman numeral, and from a string roman numeral to a int. (seen at bottom of class diagram)

Testing: Write a program that uses this class and all methods. You can assume that the input for Roman numeral is a legal string. Your test program should allow the user to enter/test more Roman numerals than the ones given in the text.

Problem 2: Line Class.

(Based on textbox chapter 1 programming problem 6)

The equation of a line in standard form is ax + by = c, where a and b both cannot be zero, and a, b, and c are real numbers. If b != 0, then –a / b is the slope of the line. If a = 0, then it is a horizontal line, and if b = 0, then it is a vertical line. The slope of a vertical line is undefined. Two lines are parallel if they have the same slope or both are vertical lines.  Two lines are perpendicular if either one of the lines is horizontal and another  is vertical, or if the product of their slopes is –1. Design the class lineType to store a line. To store a line, you need to store the values of a (coefficient of x), b (coefficient of y), and c.

For this your are to create a class called lineType. You will also need a second class Point, which is used to represent the x and y values of a point. For these class you will first need to design both classes using the diagrams.net program. The link for this repl project is here: lineType Project.

Your lineType class should permit the following operations:

  1. A default contructor lineType() (what should this do?)
  2. A constructor lineType(a,b,c)
  3. double slope()
  4. line1 == line2 – Return True if lines are equal. This returns a bool. You will need to overload the == for this. See this and this for how to do this.
  5. line1 || line2 – Return True if lines are parallel. Returns a bool.
  6. line1 | line2 – Return True if lines are perpendicular. Returns a bool.
  7. Point* intersect(line2) – This will be called as
    Point *p = line1.intersect(line2)
    and with thus return a pointer to a point where the points intersect. It should return a NULL if the lines don’t intersect.
  8. void print() – print the line information.
  9. If you feel you need other methods, add them

You can compute the intersection of two lines with:

double det = A1 * B2 - A2 * B1
if (det == 0) {
  //Lines are parallel
} else {
  double x = (B2 * C1 - B1 * C2) / det
  double y = (A1 * C2 - A2 * C1) / det
}

Note: You can represent infinity as follows:

#include <limits>
double a = std::numeric_limits<double>::infinity();

You use the point class I created for you. Using a class in another class is call “containment or composition”.

See below for what I am expecting for this and all problems in this course.

Turn in on Moodle

  1. A link to your working repl program.
  2. Your Class diagrams. You must use the diagrams.net program to create.
  3. The outputs of your test programs.

Your tests must FULLY test the the class

Grading

Requirements Grading Comments Points Score
Good Code Design
40
Tests for all functions including common and boundary cases.
30
Class Diagrams
20
Comments
10
Total
100

Requirements for all assignments

Good Code Design: Since this course is also about “program design”, this is an essential point you need to keep in mind. So, this requirement is understood and will not be repeated for future assignments.

Testing: Having solved a problem correctly may not be good enough to get full points. You need to write a good test program. This is something you need to think carefully about for each assignment. Make sure that your program tests all aspects of the assignment.

User Interface: All programs should have a well designed user interface. The program should, for example, allow the user to repeat it’s operation until the user is done. It should also validate the values entered for correct type and range.

Pair Programming: You will be working in pairs for the programming assignments in this course.

Comments: At the top of each program you submit in this course, you need to include the following information:

Each function should include comments for:

/**
    * Divides two numbers.
    * Precondition: num2 is not zero.
    * Postcondition: Returns the quotient of num1 and num2.
    * @param num1 the numerator
    * @param num2 the denominator
    * @return the quotient of num1 and num2
*/
double divide(double num1, double num2)
{
    return num1 / num2;
}