Write a program that will represent an axis-aligned

Assignment Help C/C++ Programming
Reference no: EM13165484

Write a program that will represent an axis-aligned right triangle in the x-y plane as a Class. A right triangle has a right angle (90-degree angle) and two sides adjacent to the right angle, called legs. See https://en.wikipedia.org/wiki/Right_triangle for a complete definition. In addition, an axis-aligned right triangle has one leg parallel with the x-axis and the other leg parallel with the y-axis. The location of the triangle is the vertex that connects the two legs, called the bottom left vertex. This vertex is located at the right angle and represented with the Class Point. The length
CSE1222 - Spring 2014
CSE1222 Lab 13 2
of the triangle is the length of the leg parallel with the x-axis. The height of the triangle is the
length of the leg parallel with the y-axis.
The procedure main() (see the code template triangles_template.cpp) has been written
for you (DO NOT change anything in the main() procedure) as well as the member attributes of
the Class Triangle. You will write code for the member functions of the Class Triangle and also
helper functions as indicated by the comments /* INSERT CODE HERE */.
Run triangles_solution.exe to see an example of the program.
A sample run of the program would look like this (bold indicates what the user will enter):
> triangles.exe
Enter first file name: first.txt
Enter bottom left x coordinate: 0
Enter bottom left y coordinate: 0
Enter length: 5
Enter height: 10
Enter second file name: second.txt
Enter scale factor in x direction: 2
Enter scale factor in y direction: 1.5
After running, the output file called first.txt contains:
----------------------------------------
Lower Left Vertex (0, 0)
Top Left Vertex (0, 10)
Bottom Right Vertex (5, 0)
Dimensions (5, 10)
Hypotenuse = 11.1803
Perimeter = 26.1803
----------------------------------------
and the output file called second.txt contains:
----------------------------------------
Lower Left Vertex (0, 0)
Top Left Vertex (0, 15)
Bottom Right Vertex (10, 0)
Dimensions (10, 15)
Hypotenuse = 18.0278
Perimeter = 43.0278
----------------------------------------
CSE1222 - Spring 2014
CSE1222 Lab 13 3
To view the contents of the file, type "cat first.txt" and "cat second.txt". Your program must work for any file names and any triangle attribute values entered by the user, i.e. not just the user input given in the example above.
1. The function prototypes are provided for you and must NOT be changed in any way.
2. The procedure main() is provided for you and must NOT be changed in any way.
3. Understand the class definitions for Point and Triangle.
4. Understand the algorithm in the procedure main().
5. Do NOT add more functions/procedures to the solution.
6. Each function should have a comment explaining what it does.
7. Each function parameter should have a comment explaining the parameter.
8. Write code by replacing every place /* INSERT CODE HERE */ appears with your solution.
9. Implement the member functions for the class Triangle. Use the appropriate class attributes of the class Triangle.
a. The location of the bottom left vertex is stored in the member attribute blPoint.
b. The top left vertex can be computed from blPoint and the height.
c. The bottom right vertex can be computed from blPoint and the length.
10. You may assume that the user will enter positive values for the length and height.
11. Implement the get and set member functions of the class Triangle.
12. Implement the member function hypotenuse() of the class Triangle that computes the hypotenuse of a triangle object. Use the Pythagorean Theorem to compute the length of the side of the triangle opposite to the right angle. Use the appropriate class attribute(s) of the class Triangle.
13. Implement the member function perimeter() of the class Triangle that computes the perimeter of the triangle object. Sum all three sides of the triangle. Use the appropriate class attribute(s) of the class Triangle and the member function hypotenuse().
14. Implement the member function scaleLength() of the class Triangle that computes the new value of the length as the current length weighted by the scale factor in the x direction. For example, if the current length is 2 and the scale factor is 3, the new length is 6. If the current length is 2 and the scale factor is 0.5, the new length is 1. You may assume that the scale factor will be positive. Update the length class attribute of the class Triangle.
15. Implement the member function scaleHeight() of the class Triangle that computes the new value of the height as the current height weighted by the scale factor in the y direction. You may assume that the scale factor will be positive. Update the height class attribute of the class Triangle.
16. Implement the member function write_out() of the class Triangle that writes all information about the triangle to an output file given a filename.
? Use the appropriate class attributes and member functions of the class Triangle.
? Use the file name to open the file for output. Review and use the program writeFile3.cpp discussed in class as a template for your program. (See the class slides or download the program from Carmen). Make sure to pass a C style string, not the C++ string, to the open routine. Include the C++ command "#include <fstream>" to use C++ file streams. Be sure to use the type "ofstream", not "ifstream", for your
CSE1222 - Spring 2014
CSE1222 Lab 13 4
output file streams. Check if the file was successfully opened for output. If not, print an error message and exit.
? Include the C++ command "#include <cstdlib>" to use the C++ exit command.
? CLOSE the file stream. (Note: You will lose points if you forget to close the output file stream, even though your program runs correctly).
? Important note, do not write redundant code.
17. Implement the function read_filename() that prompts, reads, and returns a file name as a string. Include the C++ command "#include <string>" to use C++ strings.
18. Implement the function read_triangle() that prompts and reads the location of the bottom left vertex, length and height. These values are assigned into the class Triangle object passed into the function using set member functions.
19. TEST YOUR CODE THOROUGHLY. For example, pay close attention to the format of the output including empty lines. Your program must not have a run-time error.
20. Be sure to add the header comments "File", "Created by", "Creation Date" and "Synopsis" at the top of the file. Each synopsis should contain a brief description of what the program does.
21. Be sure that there is a comment documenting each variable.
22. Be sure that your if statements, for and while loops and blocks are properly indented.

23.Check your output against the output from the solution executables provided

#include <iostream>
#include <cmath>

using namespace std;

class Point
{
private:
double px;
double py;

public:
void setX(const double x);
void setY(const double y);
double getX() const;
double getY() const;
};

class Triangle
{
private:
Point blPoint;
double length, height;

public:
// member functions
void setBottomLeftX(const double x);
void setBottomLeftY(const double y);
void setLength(const double inLength);
void setHeight(const double inHeight);

Point getBottomLeft() const;
Point getBottomRight() const;
Point getTopLeft() const;
double getLength() const;
double getHeight() const;

double perimeter() const;
double hypotenuse() const;
void scaleLength(const double sx);
void scaleHeight(const double sy);
void write_out(const string fname) const;
};

// FUNCTION PROTOTYPES GO HERE:
string read_filename(const string prompt);
void read_triangle(Triangle & tri);

int main()
{
// Define local variables
string fname;   // Output stream to file
Triangle tri;
double sx, sy;

// Prompt the user for the name of the first file to write
fname = read_filename("Enter first file name: ");
cout << endl;

//Prompt the user for triangle information and fill Class Triangle object, tri,
//with this information
read_triangle(tri);

// Write the triangle information to the first output file
tri.write_out(fname);
cout << endl;

// Prompt the user for the name of the second file to write and open it
fname = read_filename("Enter second file name: ");
cout << endl;

// Prompt and read scale factors to change length and height
cout << "Enter scale factor in x direction: ";
cin >> sx;

cout << "Enter scale factor in y direction: ";
cin >> sy;

// Apply scale factors
tri.scaleLength(sx);
tri.scaleHeight(sy);
cout << endl;

// Write the triangle information to the second output file
tri.write_out(fname);

return 0;
}
   
// FUNCTION DEFINITIONS GO HERE:
    
// CLASS MEMBER FUNCTION DEFINITINOS GO HERE:

void Point::setX(const double x)
{
/* INSERT YOUR CODE */
}

void Point::setY(const double y)
{
/* INSERT YOUR CODE */
}

double Point::getX() const
{
/* INSERT YOUR CODE */
}

double Point::getY() const
{
/* INSERT YOUR CODE */
}

void Triangle::setBottomLeftX(const double x)
{
/* INSERT YOUR CODE */
}

void Triangle::setBottomLeftY(const double y)
{
/* INSERT YOUR CODE */
}

void Triangle::setLength(const double inLength)
{
/* INSERT YOUR CODE */
}

void Triangle::setHeight(const double inHeight)
{
/* INSERT YOUR CODE */
}

Point Triangle::getBottomLeft() const
{
/* INSERT YOUR CODE */
}

Point Triangle::getBottomRight() const
{
/* INSERT YOUR CODE */
}

Point Triangle::getTopLeft() const
{
/* INSERT YOUR CODE */
}

double Triangle::getLength() const
{
/* INSERT YOUR CODE */
}

double Triangle::getHeight() const
{
/* INSERT YOUR CODE */
}

double Triangle::hypotenuse() const
{
/* INSERT YOUR CODE */
}

double Triangle::perimeter() const
{
/* INSERT YOUR CODE */
}

void Triangle::scaleLength(const double scalefact)
{
/* INSERT YOUR CODE */
}

void Triangle::scaleHeight(const double scalefact)
{
/* INSERT YOUR CODE */
}

void Triangle::write_out(const string fname) const
{
/* INSERT YOUR CODE */
}

string read_filename(const string prompt)
{
/* INSERT YOUR CODE */
}

void read_triangle(Triangle & tri)
{
/* INSERT YOUR CODE */
}

Reference no: EM13165484

Questions Cloud

Describe the development of the modern periodic table : Describe the development of the modern periodic table. Include contributions made by Lavoisier, Newlands, Mendeleev, and Moseley.
What gas comprises the bubbles : In a beaker of boiling water, there are many gas bubbles forming throughtout the liquid. What gas comprises the bubbles.
Which of the above costs and values mentioned are irrelevant : the company ABC Inc. bought a machine for automatic playback of " software " at a cost of $ 20,000 ( the "original cost" ) . The expectation was that the machine had a useful life of 5 years , after which have a residual value of $ 5,000 ( "salvage v..
What is the enthalpy of vaporization : A low melting metallic element has a vapor pressure of 28.2 torr at 458. oC. and a vapor pressure of 420. torr at 710. oC. What is the enthalpy of vaporization of this metal in kJ/mol?
Write a program that will represent an axis-aligned : Write a program that will represent an axis-aligned right triangle in the x-y plane as a Class. A right triangle has a right angle (90-degree angle) and two sides adjacent to the right angle, called legs. See http://en.wikipedia.org/wiki/Right_tri..
Effectiveness of an hrd program : Explain the role that trainability plays in the effectiveness of an HRD program or intervention. Briefly describe the options available to assess the trainability of employees
Class sorter which contains methods for selection sort : Write a class Sorter which contains methods for selection sort, insertion sort and bubble sort (start with the code below). Then create a client class which asks user to enter ten numbers using arrays. Then the program asks user which sorting algo..
Write a script that creates a craps game : Write a script that creates a craps game and meets the following requirements. Name the script craps.sh The script will get 2 random numbers between 1-6.
Estimate state income tax payments : Estimated state income tax payments of $1,000 each quarter and estimated city income tax payments of $300 each quarter. The Dunphys made all fourth-quarter payments on December 31, 2013. They would like to receive a refund for any overpayments.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  The funtion should take as parameters

Write a function in c ++ that multiplies two functions. the funtion should take as parameters two fraction structures. Then, the function should multiply the two fractions and return the solution as a fraction structure.

  Program that will ask for a month

Write a program that will ask for a month (1-12) and a year (yyyy). the program should then produce a calendar showing the month name and year and have all of the days displayed under it.

  Reverses the characters in a character array

Write the function reverseit that reverses the characters in a character array. You must also write main that calls reverseit.

  Accepts a pointer to a c-string as an argument

Write a function that accepts a pointer to a C-string as an argument and capitalizes the fist character of each sentence in the string. For instance, if the string argument is "hello

  For this program reads the first 11 characters

E main for this program reads the first 11 characters from input, saving them. It then reads 26 short integers into |vals|, and passes them and the characters to EmbedWatermark, which subtly alters the contents of vals to contain the characters. A..

  Program to compute gross wages for employee using array

Write program which uses the following arrays: payRate: array of seven floats to hold each employee's hourly pay rate. wages: array of seven floats to hold each employee's gross wages.

  Assign passed value to function to return value

Assign passed value to this member and another function to return value. Your main should read the integer from an input data file, and write the output to the output data file.

  Write program to declare the array of type float

Write down the c++ program which declares the array of 50 components of type float. Initialize array so that first 25 components are equal to square of the index variable.

  Create class has three pieces of information as data members

Create a class called Date in C++ that includes three pieces of information as data members: month (type int), day (type int) and yaer (type int).

  Programming assignment is to tweak the existing mammal

programming assignment is to tweak the existing Mammal program and create your own Vehicle program.

  Ng stands for next guess

Where NG stands for next guess and LG stands for last guess. Write a function that calculates the square root of a number using this method. The initial guess will be the starting value of LG .

  Modify it so it gives the ith largest number

the follow code gives the ith smallest number, how do you modify it so it gives the ith largest number ?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd