CSCI 261 - Programming Concepts (C++)

Spring 2017 - Assignment 02 - Hello Triangle

Quick Links: Blackboard | Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This assignment is due by January 24, 2017 11:59PM.

We Love Triangles



You'll soon start to figure out how much we love triangles (they have some wonderful properties). To get started, create an empty project called A02 and copy the code below for your main.cpp .

/* CSCI 261 A02: Triangles 
 * Author: XXXX (_INSERT_YOUR_NAME_HERE_)
 *
 * Add more complete description here...
 */

#include <iostream>   // For cin, cout, etc.
using namespace std;  // For standard namespace 

int main() {
    // PART I: INSERT YOUR CODE BELOW HERE
            
            
            
    // PART I INSERT YOUR CODE ABOVE HERE
    // PART II: INSERT YOUR CODE BELOW HERE

            
            
    // PART II INSERT YOUR CODE ABOVE HERE
    // PART III INSERT YOUR CODE BELOW HERE




    // PART III INSERT YOUR CODE ABOVE HERE
                          
    return 0; // signals the operating system that our program ended OK.
}

There are three short programming assignments with this homework assignment. You should put your solutions to all three of these short assignments in one main() . Please use comments above to see where code from each assignment begins/ends. Before moving on to the three parts, take time to update the header comments at the top of your main.cpp file. Also, make sure everything runs fine before moving on to the next step.


Instructions - PART I: Generate Points



Using a random number generator, first generate an (X, Y) location to represent one vertex of our triangle. Use two integer variables to store this (X, Y) location and generate random values in the range [-10, 10] for each value. Display this starting point to the user.

Then ask the user to enter two more (X, Y) values to represent the remaining two vertices of our triangle. It is possible the user could enter any real value for these values, so choose the appropriate data type.


Instructions - PART II: Calculate Some Triangle Properties



Now that we have three vertices representing a triangle, let's computer some useful properties of a triangle:
  1. Side Lengths: Using the three vertices, compute the length of each side of our triangle. (Hint: One of the equations from Lab2A could be quite useful here)
  2. Perimeter: Now that you know the side lengths, compute the perimeter of our triangle.
  3. Area: Finally, compute the area of our triangle. (Hint: Do some super-googling to find an equation that uses the sides of a triangle to compute the area)

Instructions - PART III: Print Those Properties



Excellent. Now let's print these numbers to the user. It's possible some of our calculations could be fractional in nature, so we will display two decimal places to the user at all times. To make our side lengths easy to read, we'll also need the decimal places aligned for quick comparison.

The first point is: 10 -5
Enter coordinates for the second point: 2.5 3
Enter coordinates for the third point: 5 0
Sides of the triangle are:  3.91
                            5.00
                            3.91
Perimeter of the triangle is 12.81
Area of the triangle is 7.50

Requirements: you need to use the cmath library and I/O manipulators in your solution to this assignment.


Grading Rubric


Your submission will be graded according to the following rubric.

Points Requirement Description
4 Labs completed
1 Assignment compiles
4 Three triangle vertices properly generated per above instructions
4 Side length, perimeter, area properly computed
4 Side length, perimeter, area properly displayed per above instructions
3 (1) Comments used (2) Coding style followed (3) Appropriate variable names, constants, and data types used (4) Instructions followed


Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.

For homework due on Tuesday, January 24 follow these specific steps:
  • create a directory called week02.
  • within week02, create three subdirectories: Lab02A, Lab02B, and A02.
  • within your new week02/Lab02A directory, copy in your main.cpp file from your Lab02A solution.
  • within your new week02/Lab02B directory, copy in your main.cpp file from your Lab02B solution.
  • within your new week02/A02 directory, copy in your main.cpp file from your A02 solution.
  • compress the week02 directory (see Step 3 here for details).
  • submit the week02.zip file to Blackboard (see Steps 5-10 here for details).
  • after you submit, download the file and double check it contains all that you think it contains!

This assignment is due by January 24, 2017 11:59PM.
Last Updated: 01/01/70 00:00


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0