Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

x.Hm am having a problem with my code... I have a program that is to have EIGHT

ID: 3614885 • Letter: X

Question

x.Hm am having a problem with my code... I have a program that is to have EIGHT different functions, each named as they are supposed to be below. We are currently going over 'void' and 'typed' funtions in class, as well as 'pass by value' and 'pass by reference' . I have pretty much everything written, and input was created by me with numbers like (12 45 36    12 12 12 ) with groups of three numbers. An output file was also created by the program to print results. Basically I am having a problem with my 'void' function to read the data in... And if theres anything else I have wrong I could use some help... I have all the formulas for the triangles posted as they should be... I will post a copy of the instructions, then my code... please help!!!

INSTRUCTIONS:

  • Call a function, printIdInfo, to print your personal identifying information to the screen.
  • Call the same function, printIdInfo, a second time, this time to print your personal identifying information to the output file.
  • Call a function, readData, to read from the input file the sides of a triangle. Use only one read statement to read in the values for each record (triangle).
  • If any of the first triangle’s sides are zero or less, call a function, printInvalidMsg, to print a message to the screen indicating that there were no valid input values on the file. (In other words, the sentinel was first on the file.)
  • Otherwise,
    •      As long as there are more records to process (the sides were all greater than zero):
      •      If the sides of the triangle are equal,
        •      Call a function, areaEquilateral, to calculate the area of an equilateral      triangle, and call a function, printEquilateralMsg, to write a message to the output file indicating that the triangle being processed is an equilateral triangle;
      •      otherwise,
        •      Call a function, areaTriangle, which uses Heron’s formula to calculate the area of the triangle.
      •      Call a function, perimeterTriangle, to calculate the perimeter of the triangle.
      •      Call a function, printResults, to print the input values plus the calculated values to the output file.
      •      Call the function, readData, which reads the sides of a triangle from the input file. (Read the next record--three sides of the next triangle).



CODE:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>

using namespace std;

void printIdInfo(ostream &out);
void readData(ifstream fin);
void printInvalidMsg(ofstream fout);
void printEquilateralMsg(ofstream fout);
void printResults(ofstream &);
double areaTriangle(double , double , double );
double areaEquilateral(double &);
double perimeterTriangle(double , double , double );

int main()
{
    ifstream fin;
    fin.open("prog5_inp4.txt");
    ofstream fout;
    fout.open("prog5_out4.txt");
   
    double side1,
           side2,
           side3,
           area,
           perimeter;
   
    printIdInfo(cout);
    printIdInfo(fout);
    readData(fin);
   
    if(side1 <= 0 || side2 <= 0 || side3 <= 0)
    {
         printInvalidMsg(fout);
    }
    else
    {
        while(side1 > 0 && side2 > 0 && side3 > 0)
        {
             if(side1 == side2 && side2 == side3)
             {
                  area = areaEquilateral(side1);
                  printEquilateralMsg(fout);
             }
             else
             {
                  area = areaTriangle(side1, side2, side3);
             }
            
             perimeter = perimeterTriangle(side1, side2, side3);
             printResults(fout, side1, side2, side3, area, perimeter);
             readData(fin);
        }
    }
   
    fin.close();
    fout.close();
   
    system("PAUSE>NUL");
    return 0;
}

void printIdInfo(ostream &out)
{
     out << "Gary L. Ingram "
         << "C.S.1428.004 "
         << "Due Date: 11/12/09 ";
}

void readData (ifstream fin)
{
     fin >> side1 >> side2 >> side3;
}

void printInvalidMsg(ofstream fout)
{   
     fout << "There are no valid input values on the file!";

Explanation / Answer

please rate - thanks

I didn't check the math, the file was created, the program runs tocompletion
many of your functions were missing correct parameters


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>

using namespace std;

void printIdInfo(ostream &out);
void readData(ifstream &fin,double&,double&,double&);
void printInvalidMsg(ofstream &fout);
void printEquilateralMsg(ofstream &fout);
void printResults(ofstream &,double,double,double,double,double);
double areaTriangle(double , double , double );
double areaEquilateral(double &);
double perimeterTriangle(double , double , double );

int main()
{
    ifstream fin;
    fin.open("prog5_inp4.txt");
    ofstream fout;
    fout.open("prog5_out4.txt");

    double side1,
          side2,
          side3,
          area,
          perimeter;

    printIdInfo(cout);
    printIdInfo(fout);
    readData(fin,side1,side2,side3);
   
    if(side1 <= 0 || side2 <= 0 || side3 <=0)
    {
        printInvalidMsg(fout);
    }
    else
    {
        while(side1 > 0&& side2 > 0 && side3 > 0)
        {
            if(side1 == side2 && side2 == side3)
            {
                 area = areaEquilateral(side1);
                 printEquilateralMsg(fout);
            }
            else
            {
                 area = areaTriangle(side1, side2, side3);
            }
           
            perimeter = perimeterTriangle(side1, side2, side3);
            printResults(fout, side1, side2, side3, area, perimeter);
            readData(fin,side1,side2,side3);
        }
    }

    fin.close();
    fout.close();

    system("PAUSE>NUL");
    return 0;
}

void printIdInfo(ostream &out)
{
     out << "Gary L. Ingram "
         <<"C.S.1428.004 "
         << "DueDate: 11/12/09 ";
}

void readData (ifstream &fin, double & side1,double &side2,double & side3)
{
     fin >> side1 >> side2 >>side3;
}

void printInvalidMsg(ofstream &fout)
{
     fout << "There are no valid inputvalues on the file!";
}

void printEquilateralMsg(ofstream &fout)
{
     fout << "This triangle is anEquilateral Triangle.";
}

void printResults(ofstream &fout, double side1, double side2,double side3, double area, double perimeter)
{
         
     fout << "The sides of the triangleare " << side1 << ", "
          << side2 << " and " << side3 << "."<< endl
          << "The area of the triangle is " << area << "."<< endl
          << "The perimeter of the triangle is " << perimeter
          << "." << endl;
}

double areaTriangle(double side1,double side2,double side3)
{
     double area,
           s;
     s = perimeterTriangle (side1, side2,side3) / 2.0;
     area = sqrt ( s * ( s - side1 ) * ( s -side2 ) * ( s - side3 ) );
     return area;
}

double areaEquilateral(double &side1)
{
     double area;
     area = ( side1 * side1 * sqrt (3) ) / 4;
     return area;
}

double perimeterTriangle(double side1, double side2, doubleside3)
{
     double perimeter;
     perimeter = side1 + side2 + side3;
     return perimeter;
}