hey guys/gals. i get a segmentation fault whenever the for loop in the print function is executed. any suggestions? im not sure what i did wrong.
//class member functions
#include "experiment.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int Experiment::numberOfTests = 0;
Experiment::Experiment(){}
void Experiment::setExpName()
{
cout << "\nPlease enter a tag name for this experiment: ";
cin >> name;
}
string Experiment::getExpName()
{
return name;
}
void Experiment::setPersonForExperiment()
{
cout << "Please enter the name of person responsible for conducting this experiment: ";
cin >> who;
}
string Experiment::getPersonForExperiment()
{
return who;
}
void Experiment::setNumOfTests()
{
numberOfTests++;
}
int Experiment::getNumOfTests()
{
return numberOfTests;
}
void Experiment::runExperiment()
{ char answer;
char decision;
cout << "Welcome to the \"I want to be Happy Experiment\" ";
cout << "\nDo you want to enter a new experiement?(Y/N)";
cin >> answer;
while(answer == 'Y')
{
setExpName();
setPersonForExperiment();
date.setExpDate();
do{
cout << "\tEnter (W) to enter Weather data, (S) to enter Sports data or (E) to end: ";
cin >> decision;
if(decision == 'W')
{
WeatherTest wtest;
tests[getNumOfTests()] = &wtest;
tests[getNumOfTests()]->getTestInfo();
setNumOfTests();
cout << "\n";
} else if(decision == 'S')
{
SportTest stest;
tests[getNumOfTests()] = &stest;
tests[getNumOfTests()]->getTestInfo();
setNumOfTests();
cout << "\n";
}
}while(decision != 'E');
char choice;
cout << "\n\tDo you want to save this information in a file(Y/N)?";
cin >> choice;
createFile(choice);
cout << "\n\tDo you still want to enter another experiment(Y/N)?";
cin >> answer;
print();
}
}
void Experiment::print()
{
cout << left << "Name: " << getExpName() << right << setw(50) << "Date: ";
date.print();
cout << endl << fixed;
cout << left << "Who: " << getPersonForExperiment() << right << setw(60) << "Total Tests Entered: " << getNumOfTests() << endl << fixed;
cout << "\nDate" << setw(15) << "Tester" << setw(15) << "Data" << setw(15) << "pos" << setw(15) << "neg" << setw(15) << "ind" << endl;
for( int i = 0; i < getNumOfTests(); i++)
{
tests[i]->print();
}
}