Ok here it is.
Main Program (assign3.cpp):
Code:
#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include "funcs3.h"
using namespace std;
// A calculator that solves multiple quadratic equations.
void readCoeffs(double coeffs[]);
struct calcRoots(double coeffs[], double roots[]);
void displayvalues(double coeffs[], double roots[]);
void toFile(double coeffs[], double roots[], ofstream outp);
main(int Nc, char* Nv[]) {
ofstream outp; // declaring an output file stream
ifstream inp; // input file stream
double coeffs[3], roots[2];
// if (Nc != 2) {
for (int count = 0; count <= Nc; count++) {
readCoeffs(coeffs);
struct calcRoots(coeffs, roots);
void displayValues(coeffs, roots);
void toFile(coeffs, roots, ofstream outp);
}
}
funcs3.cpp :
Code:
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
void readCoeffs(double coeffs[]);
struct calcRoots(double coeffs[], double roots[]);
void displayvalues(double coeffs[], double roots[]);
void toFile(double coeffs[], double roots[], ofstream outp);
void readCoeffs(double coeffs[]) {
cout << "Enter coefficient a: " << endl;
cin >> coeffs[0];
cout << "Enter coefficient b: " << endl;
cin >> coeffs[1];
cout << "Enter coefficient c: " << endl;
cin >> coeffs[2];
cout << endl;
}
struct calcRoots(double coeffs[], double roots[]) {
double root1 = ((-coeffs[1]+sqrt((coeffs[1]*coeffs[1])-(4*coeffs[0]*coeffs[2])))/(2*coeffs[0]));
double root2 = ((-coeffs[1]-sqrt((coeffs[1]*coeffs[1])-(4*coeffs[0]*coeffs[2])))/(2*coeffs[0]));
roots[0] = root1;
roots[1] = root2;
double dscr();
}
double dscr(double coeffs[]) {
double dscrResult = ((coeffs[1]*coeffs[1])-(4*coeffs[0]*coeffs[2]));
return dscrResult;
}
void displayValues(double coeffs[], double roots[]) {
if (sqrt((coeffs[1]*coeffs[1])-(4*coeffs[0]*coeffs[2])) >= 0) {
cout << "The solutions of a quadratic equation with coefficients: " << endl;
cout << "a = " << coeffs[0] << " b = " << coeffs[1] << " c = " << coeffs[2] << endl;
cout << "are as follows " << endl;
cout << "Root 1: " << roots[0] << endl;
cout << "Root 2: " << roots[1] << endl;
cout << endl;
}
else {
cout << "The solution of a quadratic equation with coefficients: " << endl;
cout << "a = " << coeffs[0] << " b = " << coeffs[1] << " c = " << coeffs[2] << endl;
cout << "does not exist in the real domain. " << endl;
cout << endl;
}
}
void toFile(double a, double b, double c, double root1, double root2, ofstream outp) {
outp.open("results.dat", ios::app);
outp << "a = " << a << " b = " << b << " c = " << c << endl;
outp << "Root1 = " << root1 << " Root2 = " << root2 << endl;
outp << endl;
outp.close();
}
and the error messages while compiling :
In file included from assign3.cpp:7:
funcs3.h:11: error: expected unqualified-id before âdoubleâ
funcs3.h:11: error: expected `)' before âdoubleâ
funcs3.h:27: error: expected unqualified-id before âdoubleâ
funcs3.h:27: error: expected `)' before âdoubleâ
assign3.cpp:13: error: expected unqualified-id before âdoubleâ
assign3.cpp:13: error: expected `)' before âdoubleâ
assign3.cpp: In function âint main(int, char**)â:
assign3.cpp:28: error: expected primary-expression before âstructâ
assign3.cpp:28: error: expected `;' before âstructâ
assign3.cpp:29: error: variable or field âdisplayValuesâ declared void
assign3.cpp:30: error: variable or field âtoFileâ declared void
assign3.cpp:30: error: expected primary-expression before âoutpâ
funcs3.h:11: error: expected unqualified-id before âdoubleâ
funcs3.h:11: error: expected `)' before âdoubleâ
funcs3.h:27: error: expected unqualified-id before âdoubleâ
funcs3.h:27: error: expected `)' before âdoubleâ
funcs3.h: In function âvoid toFile(double, double, double, double, double, std:fstream)â:
funcs3.h:58: error: âoutpâ has incomplete type
/usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/iosfwd:89: error: declaration of âstruct std:fstreamâ
The smilies are a : and O right next to each other.