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 #include #include #include #include #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 sides) { return (sides[SIDEA] >= MIN_LENGTH || sides[SIDEB] >= MIN_LENGTH || sides[HYPOTENUSE] >= MIN_LENGTH); }

// Checks if the passed in triangle has 3 sides bool hasValidSides(vector sides) { return sides.size() == REQ_SIDES; }

// Returns true if the 2 sides are longer than longest sides bool fufillsTriangleInequality(vector sides) { return (sides[SIDEA] + sides[SIDEB]) > sides[HYPOTENUSE]; }

// Returns true if all conditions above are fulfilled bool isTriangle(vector sides) { return hasValidSides(sides) && isValidLength(sides) && fufillsTriangleInequality(sides); }

// Returns true if 2 sides are the same // Expects integer vector with three sides bool isIsosceles(vector sides) { return(sides[SIDEA] == sides[SIDEB] || sides[SIDEA] == sides[HYPOTENUSE] || sides[SIDEB] == sides[HYPOTENUSE]); }

// Returns true if all sides are the same // Expects integer vector with three sides bool isEquilateral(vector sides) { return (sides[SIDEA] == sides[SIDEB] && sides[SIDEA] == sides[HYPOTENUSE]); }

// 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 createSortedTriangle(string fileText) { int side; vector sides; istringstream fileTextStream(fileText);

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 triangle) { string tString = to_string(triangle[SIDEA]) + " " + to_string(triangle[SIDEB]) + " " + to_string(triangle[HYPOTENUSE]); return tString; }

// 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 triangle) { if (isTriangle(triangle)) { if (isEquilateral(triangle)) return printTriangle(triangleString(triangle), "equilateral!"); if (isIsosceles(triangle)) return printTriangle(triangleString(triangle), "isosceles!"); return printTriangle(triangleString(triangle), "scalene!"); }

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 triangle;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!