Question: The program is already done. Please complete the flow graph and cyclomatic complexity, a short description of how to generate the test cases from the
The program is already done. Please complete the flow graph and cyclomatic complexity, a short description of how to generate the test cases from the flow graph, and the test case file.
For the function that computes the triangle type, do the following:
Draw a flow graph.
Calculate the cyclomatic complexity, and show how you did it.
Generate a set of test cases from the flow graph.
Turn in the test cases in a file in the above format. The test case file can be used as input to such a program (both yours and mine!) Expected results shall be documented with a comment line before each test case.
Here is the requirements for the code The code is written and the program is done.
Write a program that tells you what type of a triangle you have.
Write it as follows:
The main program input from a file, and passes three (signed) integers to a function that computes the type of triangle. Besides writing the whole program, your task is to test the function using white box testing techniques.
Have the program prompt for a file name, and read sets of three numbers from the file, reporting on triangle types until the file ends.
You may assume the following:
The file exists
All the inputs are integers. However, they might be negative
The file contains the proper number of entries (a multiple of 3)
The file contains three numbers per line.
Lines that begin with a # are comments, and should simply be echoed.
Results are sent to the standard out. (The function does the output.)
#include
using namespace std;
// After the vector is sorted, these are the corresponding indexes const int SIDEA = 0; const int SIDEB = 1; const int HYPOTENUSE = 2;
// Triangles have to have side lengths >= 1 and 3 sides. const int MIN_LENGTH = 1; const int REQ_SIDES = 3;
// Comments start with '#' const char COMMENT_CHAR = '#';
// Checks each side to verify minimum length >= 1 bool isValidLength(vector
// Checks if the passed in triangle has 3 sides bool hasValidSides(vector
// Returns true if the 2 sides are longer than longest sides bool fufillsTriangleInequality(vector
// Returns true if all conditions above are fulfilled bool isTriangle(vector
// Returns true if 2 sides are the same // Expects integer vector with three sides bool isIsosceles(vector
// Returns true if all sides are the same // Expects integer vector with three sides bool isEquilateral(vector
// Returns true if a string starts with '#' bool isComment(string line) { return (line[0] == COMMENT_CHAR); }
// Gets input until a valid filename is provided // Returns filename string getFileName() { string fileName; do { cin.clear(); cin >> fileName;
if (cin.fail()) { cout << "Please enter a valid file name" << endl; cin.ignore(500, ' '); } } while (cin.fail());
return fileName; }
// Sorts a vector representation of triangle side lengths in ascending order // Returns the sorted triangle vector vector
while (fileTextStream >> side) { sides.push_back(side); } sort(sides.begin(), sides.end()); return sides; }
// Little helper function to convert vector values to string string triangleString(vector
// Another helper function to combine triangleString (above) and the calculated type string printTriangle(string triangleString, string type) { return "Triangle " + triangleString + " is " + type; }
// Wrapper function for some of the boolean functions above; determines triangle type // Returns a string with triangle type string calculateTriangleType(vector
return printTriangle("on this line", "not a triangle"); }
// Processes the passed in file line by line; determines if a line is a comment or triangle // If comment, prints it out. Otherwise it will sort/push values into a vector and calculate // The corresponding triangle type; prints out the string. void processTriangle(ifstream& triangleFile) { string fileText;
while (getline(triangleFile, fileText)) { vector
if (isComment(fileText)) { cout << fileText << endl; } else { triangle = createSortedTriangle(fileText); cout << calculateTriangleType(triangle) << endl; } } }
int main(int argc, char* argv[]) { ifstream triangleFile; string fileName;
cout << "Welcome to triangle identifier. Please input file name: "; fileName = getFileName(); triangleFile.open(fileName);
while (!triangleFile.is_open()) { cout << "That doesn't seem to be a valid file name; try again: "; fileName = getFileName(); triangleFile.open(fileName); }
cout << " " << endl; processTriangle(triangleFile); triangleFile.close();
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
