Question
So this first part of the code is the main.cpp which is used to test if your code works or not #include #include #include BirthAnalysis.h
So this first part of the code is the main.cpp which is used to test if your code works or not
#include
using std::string; using std::endl; using std::cout;
bool testAnswer(const string &nameOfTest, double received, double expected);
template
int main() { { cout << "Testing with small data file ..." << endl; BirthAnalysis ba; ba.readFile("data1.txt");
testAnswer("numberOfBirths in Stanislaus_County", ba.numberOfBirths("Stanislaus_County"), 2); testAnswer("numberOfBirths in Sutter_County", ba.numberOfBirths("Sutter_County"), 3);
testAnswer("smallestBirthLength in Stanislaus_County", ba.smallestBirthLength("Stanislaus_County"), 46.2); testAnswer("smallestBirthLength in Sutter_County", ba.smallestBirthLength("Sutter_County"), 47.2);
testAnswer("isUnderweightBirth in Stanislaus_County", ba.isUnderweightBirth("Stanislaus_County"), true); testAnswer("isUnderweightBirth in Sutter_County", ba.isUnderweightBirth("Sutter_County"), false); } { cout << "Testing with large data file ..." << endl; BirthAnalysis ba; ba.readFile("data2.txt");
testAnswer("numberOfBirths in Calaveras_County", ba.numberOfBirths("Calaveras_County"), 81); testAnswer("numberOfBirths in Sutter_County", ba.numberOfBirths("Sutter_County"), 40);
testAnswer("smallestBirthLength in Calaveras_County", ba.smallestBirthLength("Calaveras_County"), 44.0); testAnswer("smallestBirthLength in Sutter_County", ba.smallestBirthLength("Sutter_County"), 44.5838);
testAnswer("isUnderweightBirth in Calaveras_County", ba.isUnderweightBirth("Calaveras_County"), true); testAnswer("isUnderweightBirth in Sutter_County", ba.isUnderweightBirth("Sutter_County"), true); } // system("pause"); // uncomment to pause main program for testing in Visual Studio return (0); }
template
bool testAnswer(const string &nameOfTest, double received, double expected) { if ((received - expected) > -0.01 && (received - expected) < 0.01) { cout << "PASSED " << nameOfTest << ": expected and received " << received << endl; return true; } cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl; return false; }
//BirthAnalysis.h
#include
class BirthAnalysis{ public: std::vector
}
BirthAnalysis(){// this is the default constructor and im not sure what im supposed to put here if anything at all county = " "; birthweight = " "; birthlength = 0; }
first.txt
Kings_County 3.258 51.2 Stanislaus_County 2.232 46.2 Sutter_County 2.584 47.2 Del_Norte_County 3.247 52.0 Santa_Clara_County 1.888 43.8 Sutter_County 3.267 49.7 Tulare_County 3.852 49.7 Stanislaus_County 3.767 52.5 San_Joaquin_County 3.733 52.6 Sutter_County 3.267 50.9
2nd.txt
Kings_County 3.258 48.28674424 Stanislaus_County 2.532 51.64454254 Sutter_County 2.584 44.5838034 Del_Norte_County 3.247 53.8321178 Santa_Clara_County 1.888 44.47600492 Sutter_County 3.267 45.18859061 Tulare_County 3.852 51.01353402 Stanislaus_County 3.767 53.47335129 San_Joaquin_County 3.733 50.6191995 Trinity_County 3.326 51.76454037 Monterey_County 4.394 45.85724134 Orange_County 3.264 50.3318612 Santa_Barbara_County 3.336 47.9379785 San_Diego_County 3.678 53.24565318 Placer_County 2.804 49.82538416 Sonoma_County 2.583 46.00442068 Yolo_County 3.742 47.05006508 Ventura_County 2.743 44.42751088 San_Luis_Obispo_County 3.201 52.42493046 Kings_County 2.566 51.64355569 Calaveras_County 3.54 49.65504037 Del_Norte_County 2.794 45.48430604
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started