SlideShare a Scribd company logo
Solve the coding errors for upvote
make test-stats
g++ -g -std=c++14 -Wall -Werror=return-type -Werror=uninitialized -Wno-sign-compare -o test-
stats stats.o week-data.o test/catch/catch.o test/test-stats.o
Undefined symbols for architecture x86_64:
"stDev(WeekData*, int)", referenced from:
C_A_T_C_H_T_E_S_T_2() in test-stats.o
C_A_T_C_H_T_E_S_T_4() in test-stats.o
"getMean(WeekData*, int)", referenced from:
C_A_T_C_H_T_E_S_T_0() in test-stats.o
C_A_T_C_H_T_E_S_T_4() in test-stats.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test-stats] Error 1
make test-state
g++ -g -std=c++14 -Wall -Werror=return-type -Werror=uninitialized -Wno-sign-compare -c -o
state.o state.cpp
state.cpp:65:12: error: no member named 'stDev' in 'State'; did you mean simply 'stDev'?
return State::stDev(weeks, numberOfDataPoints);
^~~~~~~~~~~~
stDev
./stats.hpp:5:19: note: 'stDev' declared here
static double stDev(WeekData* weeks, int count);
^
1 error generated.
make: *** [state.o] Error 1
make test-morbidity
g++ -g -std=c++14 -Wall -Werror=return-type -Werror=uninitialized -Wno-sign-compare -c -o
state.o state.cpp
state.cpp:65:12: error: no member named 'stDev' in 'State'; did you mean simply 'stDev'?
return State::stDev(weeks, numberOfDataPoints);
^~~~~~~~~~~~
stDev
./stats.hpp:5:19: note: 'stDev' declared here
static double stDev(WeekData* weeks, int count);
^
1 error generated.
make: *** [state.o] Error 1
Code
test-morbidity.cpp
#include "catch/catch.hpp"
#include "../morbidity.hpp"
const std::string INVALID_STATE = "foo";
TEST_CASE("Testing Morbidity class")
{
Morbidity dataset;
CHECK(!dataset.load("foo.bar"));
CHECK(dataset.load("data.csv"));
CHECK(Approx(-1.0) == dataset.getMean(INVALID_STATE));
CHECK(Approx(1036.78).epsilon(0.01) == dataset.getMean("Alabama"));
CHECK(Approx(81.17).epsilon(0.01) == dataset.getMean("Alaska"));
CHECK(16 == dataset.getStateOutlierCount("Alabama"));
auto outliers = dataset.getStateOutliers("Alabama");
CHECK("2020-07-25 - total deaths: 1333" == outliers.at(0));
CHECK("2021-02-06 - total deaths: 1503" == outliers.at(12));
CHECK_THAT(dataset.getOutlierInfoForAllStates(), Catch::Contains("West Virginia: 19"));
}
test-state.cpp
#include
#include "../state.hpp"
#include "catch/catch.hpp"
TEST_CASE("Testing State class on calculation") {
State bama("Alabama");
CHECK("Alabama" == bama.getName());
bama.addWeek("2020-05-02,2000");
bama.addWeek("2020-05-09,2000");
bama.addWeek("2020-05-16,100");
bama.addWeek("2020-05-23,2000");
bama.addWeek("2020-05-30,2000");
bama.addWeek("2020-06-06,2000");
CHECK(Approx(1683.33).epsilon(0.01) == bama.getMeanDeaths());
CHECK(Approx(708.08).epsilon(0.01) == bama.getStDev());
CHECK(1 == bama.getOutlierCount());
auto outliers = bama.getOutlierInfos();
CHECK("2020-05-16 - total deaths: 100" == outliers.at(0));
}
TEST_CASE("Testing State class on rule of three") {
State bama("Alabama");
CHECK("Alabama" == bama.getName());
State bama1(bama);
CHECK("Alabama" == bama1.getName());
State bama2;
bama2 = bama;
CHECK("Alabama" == bama2.getName());
}
test-stats.cpp
#include "catch/catch.hpp"
#include "../stats.hpp"
#include "../week-data.hpp"
WeekData data[] = {
WeekData("1776-07-04,1"), // Just some static test data.
WeekData("1776-07-11,2"), // The dates are not important
WeekData("1776-07-18,3"), // since we are just trying to test the
WeekData("1776-07-25,5"), // statistical calculations
WeekData("1776-08-02,6")
};
TEST_CASE("Testing Mean")
{
// Comparing doubles, can use Approx() to allow some epsilon difference
CHECK(Approx(3.4) == getMean(data, 5));
}
TEST_CASE("Testing Stdev")
{
CHECK(Approx(1.85).epsilon(0.01) == stDev(data, 5));
}
TEST_CASE("Testing empty list")
{
// let's call the getMean of no numbers: 0
CHECK(Approx(0) == getMean({}, 0));
CHECK(Approx(0) == stDev({}, 0));
}
// Compile & run:
// make clean test
morbidity.cpp
#include "morbidity.hpp"
#include "state.hpp"
#include
#include
Morbidity::Morbidity() : numberOfStates(0), states(nullptr) {
}
Morbidity::~Morbidity() {
for (int i = 0; i < numberOfStates; i++) {
delete states[i];
}
delete[] states;
}
bool Morbidity::load(const std::string& filename) {
std::ifstream file(filename);
if (!file.is_open()) {
return false;
}
std::string line;
std::string stateName;
while (std::getline(file, line)) {
std::istringstream iss(line);
std::string state, weekData;
std::getline(iss, state, ',');
std::getline(iss, weekData);
if (state != stateName) {
stateName = state;
State* newState = new State(stateName);
if (numberOfStates < 65) {
if (states == nullptr) {
states = new State*[65];
}
states[numberOfStates] = newState;
numberOfStates++;
}
}
try {
int deaths = std::stoi(weekData);
if (states != nullptr) {
states[numberOfStates - 1]->addWeek(weekData);
}
} catch (const std::invalid_argument& e) {
}
}
file.close();
return true;
}
double Morbidity::getMean(const std::string& stateName) const {
for (int i = 0; i < numberOfStates; i++) {
if (states[i]->getName() == stateName) {
return states[i]->getMeanDeaths();
}
}
return -1.0;
}
int Morbidity::getStateOutlierCount(const std::string& stateName) const {
for (int i = 0; i < numberOfStates; i++) {
if (states[i]->getName() == stateName) {
return states[i]->getOutlierCount();
}
}
return 0;
}
std::vector Morbidity::getStateOutliers(const std::string& stateName) const {
for (int i = 0; i < numberOfStates; i++) {
if (states[i]->getName() == stateName) {
return states[i]->getOutlierInfos();
}
}
return std::vector();
}
std::string Morbidity::getOutlierInfoForAllStates() const {
std::string outlierInfo;
for (int i = 0; i < numberOfStates; i++) {
outlierInfo += states[i]->getName() + ": " + std::to_string(states[i]->getOutlierCount()) + "
outlying weeksn";
}
return outlierInfo;
}
morbidity.hpp
#ifndef MORBIDITY_HPP
#define MORBIDITY_HPP
#include
#include
class State;
class Morbidity {
public:
Morbidity();
~Morbidity();
bool load(const std::string& filename);
double getMean(const std::string& stateName) const;
int getStateOutlierCount(const std::string& stateName) const;
std::vector getStateOutliers(const std::string& stateName) const;
std::string getOutlierInfoForAllStates() const;
private:
int numberOfStates;
State** states;
};
#endif
state.cpp
#include "state.hpp"
#include "week-data.hpp"
#include "stats.hpp"
State::State() : name(""), weeks(nullptr), numberOfDataPoints(0) {
// Default constructor
}
State::State(std::string name) : name(name), numberOfDataPoints(0) {
// Constructor with a name
weeks = new WeekData[500]; // Assuming a maximum of 500 data points
}
State::State(const State& rhs) : name(rhs.name), numberOfDataPoints(rhs.numberOfDataPoints)
{
// Copy constructor
weeks = new WeekData[500];
for (int i = 0; i < numberOfDataPoints; i++) {
weeks[i] = rhs.weeks[i];
}
}
State& State::operator=(const State& rhs) {
// Assignment operator
if (this == &rhs) {
return *this;
}
name = rhs.name;
numberOfDataPoints = rhs.numberOfDataPoints;
if (weeks) {
delete[] weeks;
}
weeks = new WeekData[500];
for (int i = 0; i < numberOfDataPoints; i++) {
weeks[i] = rhs.weeks[i];
}
return *this;
}
State::~State() {
// Destructor
delete[] weeks;
}
std::string State::getName() const {
return name;
}
void State::addWeek(std::string weekData) {
// Implement function to add week data
if (numberOfDataPoints < 500) {
weeks[numberOfDataPoints] = WeekData(weekData);
numberOfDataPoints++;
}
}
double State::getMeanDeaths() const {
return /*State::*/getMean(weeks, numberOfDataPoints);
}
double State::getStDev() const {
return State::stDev(weeks, numberOfDataPoints);
}
int State::getOutlierCount() const {
int outlierCount = 0;
double mean = getMeanDeaths();
double stDeviation = getStDev();
for (int i = 0; i < numberOfDataPoints; i++) {
if (std::abs(weeks[i].getDeathCount() - mean) > 2 * stDeviation) {
outlierCount++;
}
}
return outlierCount;
}
std::vector State::getOutlierInfos() const {
std::vector outlierInfos;
double mean = getMeanDeaths();
double stDeviation = getStDev();
for (int i = 0; i < numberOfDataPoints; i++) {
if (std::abs(weeks[i].getDeathCount() - mean) > 2 * stDeviation) {
outlierInfos.push_back(weeks[i].info());
}
}
return outlierInfos;
}
state.hpp
#ifndef STATE_HPP
#define STATE_HPP
#include
#include
class WeekData;
class State {
public:
State();
State(std::string name);
State(const State& rhs);
State& operator=(const State& rhs);
~State();
std::string getName() const;
void addWeek(std::string weekData);
double getMeanDeaths() const;
double getStDev() const;
int getOutlierCount() const;
std::vector getOutlierInfos() const;
private:
std::string name;
WeekData* weeks;
int numberOfDataPoints;
};
#endif
stats.cpp
#include "stats.hpp"
#include "week-data.hpp"
#include
double /*Stats::*/getMean(WeekData* weeks, int count) {
double sum = 0.0;
for (int i = 0; i < count; i++) {
sum += weeks[i].getDeathCount();
}
return sum / count;
}
double /*Stats::*/stDev(WeekData* weeks, int count) {
double mean = getMean(weeks, count);
double sumSquaredDiffs = 0.0;
for (int i = 0; i < count; i++) {
double diff = weeks[i].getDeathCount() - mean;
sumSquaredDiffs += diff * diff;
}
double variance = sumSquaredDiffs / count;
return std::sqrt(variance);
}
stats.hpp
#ifndef STATS_HPP
#define STATS_HPP
#include "week-data.hpp"
static double getMean(WeekData* weeks, int count);
static double stDev(WeekData* weeks, int count);
#endif

More Related Content

Similar to Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf

a) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfa) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdf
nageswara1958
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
Chen-Hung Hu
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
PVS-Studio LLC
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
Chhom Karath
 
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizationsEgor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
Kevlin Henney
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
kirthika jeyenth
 
R Language
R LanguageR Language
R Language
ShwetDadhaniya1
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsphanleson
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
mohd_mizan
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
Kyung Yeol Kim
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
corehard_by
 
Chapter 2
Chapter 2Chapter 2
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
Prof. Dr. K. Adisesha
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
GlobalLogic Ukraine
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
Andrey Karpov
 

Similar to Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf (20)

a) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdfa) Write the recursive function in C++ to sort a set of data using M.pdf
a) Write the recursive function in C++ to sort a set of data using M.pdf
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizationsEgor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
 
R Language
R LanguageR Language
R Language
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
pointers 1
pointers 1pointers 1
pointers 1
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 

More from snewfashion

Simulation rules are almost the same to what I coded using Python bu.pdf
Simulation rules are almost the same to what I coded using Python bu.pdfSimulation rules are almost the same to what I coded using Python bu.pdf
Simulation rules are almost the same to what I coded using Python bu.pdf
snewfashion
 
Sergio and Malena were married for 10 years before Malena unexpected.pdf
Sergio and Malena were married for 10 years before Malena unexpected.pdfSergio and Malena were married for 10 years before Malena unexpected.pdf
Sergio and Malena were married for 10 years before Malena unexpected.pdf
snewfashion
 
Seg�n Bauer (2004), los sistemas de incorporaci�n var�an desde un en.pdf
Seg�n Bauer (2004), los sistemas de incorporaci�n var�an desde un en.pdfSeg�n Bauer (2004), los sistemas de incorporaci�n var�an desde un en.pdf
Seg�n Bauer (2004), los sistemas de incorporaci�n var�an desde un en.pdf
snewfashion
 
Select Your Tool Choose the tool that suits your preference�whether.pdf
Select Your Tool Choose the tool that suits your preference�whether.pdfSelect Your Tool Choose the tool that suits your preference�whether.pdf
Select Your Tool Choose the tool that suits your preference�whether.pdf
snewfashion
 
Sarasota Company has decided to expand its operations. The bo Prepar.pdf
Sarasota Company has decided to expand its operations. The bo Prepar.pdfSarasota Company has decided to expand its operations. The bo Prepar.pdf
Sarasota Company has decided to expand its operations. The bo Prepar.pdf
snewfashion
 
reword this paragraph The �digital divide� is a term used to descr.pdf
reword this paragraph  The �digital divide� is a term used to descr.pdfreword this paragraph  The �digital divide� is a term used to descr.pdf
reword this paragraph The �digital divide� is a term used to descr.pdf
snewfashion
 
Scenario 3 Urgent Care CenterImplement and plan steps necessary f.pdf
Scenario 3 Urgent Care CenterImplement and plan steps necessary f.pdfScenario 3 Urgent Care CenterImplement and plan steps necessary f.pdf
Scenario 3 Urgent Care CenterImplement and plan steps necessary f.pdf
snewfashion
 
Requirement 2. Prepare a statement of stockholders equity forCent.pdf
Requirement 2. Prepare a statement of stockholders equity forCent.pdfRequirement 2. Prepare a statement of stockholders equity forCent.pdf
Requirement 2. Prepare a statement of stockholders equity forCent.pdf
snewfashion
 
Task 5 Policy review 5 Why might the health and safety policy requi.pdf
Task 5 Policy review 5 Why might the health and safety policy requi.pdfTask 5 Policy review 5 Why might the health and safety policy requi.pdf
Task 5 Policy review 5 Why might the health and safety policy requi.pdf
snewfashion
 

More from snewfashion (9)

Simulation rules are almost the same to what I coded using Python bu.pdf
Simulation rules are almost the same to what I coded using Python bu.pdfSimulation rules are almost the same to what I coded using Python bu.pdf
Simulation rules are almost the same to what I coded using Python bu.pdf
 
Sergio and Malena were married for 10 years before Malena unexpected.pdf
Sergio and Malena were married for 10 years before Malena unexpected.pdfSergio and Malena were married for 10 years before Malena unexpected.pdf
Sergio and Malena were married for 10 years before Malena unexpected.pdf
 
Seg�n Bauer (2004), los sistemas de incorporaci�n var�an desde un en.pdf
Seg�n Bauer (2004), los sistemas de incorporaci�n var�an desde un en.pdfSeg�n Bauer (2004), los sistemas de incorporaci�n var�an desde un en.pdf
Seg�n Bauer (2004), los sistemas de incorporaci�n var�an desde un en.pdf
 
Select Your Tool Choose the tool that suits your preference�whether.pdf
Select Your Tool Choose the tool that suits your preference�whether.pdfSelect Your Tool Choose the tool that suits your preference�whether.pdf
Select Your Tool Choose the tool that suits your preference�whether.pdf
 
Sarasota Company has decided to expand its operations. The bo Prepar.pdf
Sarasota Company has decided to expand its operations. The bo Prepar.pdfSarasota Company has decided to expand its operations. The bo Prepar.pdf
Sarasota Company has decided to expand its operations. The bo Prepar.pdf
 
reword this paragraph The �digital divide� is a term used to descr.pdf
reword this paragraph  The �digital divide� is a term used to descr.pdfreword this paragraph  The �digital divide� is a term used to descr.pdf
reword this paragraph The �digital divide� is a term used to descr.pdf
 
Scenario 3 Urgent Care CenterImplement and plan steps necessary f.pdf
Scenario 3 Urgent Care CenterImplement and plan steps necessary f.pdfScenario 3 Urgent Care CenterImplement and plan steps necessary f.pdf
Scenario 3 Urgent Care CenterImplement and plan steps necessary f.pdf
 
Requirement 2. Prepare a statement of stockholders equity forCent.pdf
Requirement 2. Prepare a statement of stockholders equity forCent.pdfRequirement 2. Prepare a statement of stockholders equity forCent.pdf
Requirement 2. Prepare a statement of stockholders equity forCent.pdf
 
Task 5 Policy review 5 Why might the health and safety policy requi.pdf
Task 5 Policy review 5 Why might the health and safety policy requi.pdfTask 5 Policy review 5 Why might the health and safety policy requi.pdf
Task 5 Policy review 5 Why might the health and safety policy requi.pdf
 

Recently uploaded

Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 

Recently uploaded (20)

Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 

Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf

  • 1. Solve the coding errors for upvote make test-stats g++ -g -std=c++14 -Wall -Werror=return-type -Werror=uninitialized -Wno-sign-compare -o test- stats stats.o week-data.o test/catch/catch.o test/test-stats.o Undefined symbols for architecture x86_64: "stDev(WeekData*, int)", referenced from: C_A_T_C_H_T_E_S_T_2() in test-stats.o C_A_T_C_H_T_E_S_T_4() in test-stats.o "getMean(WeekData*, int)", referenced from: C_A_T_C_H_T_E_S_T_0() in test-stats.o C_A_T_C_H_T_E_S_T_4() in test-stats.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [test-stats] Error 1 make test-state g++ -g -std=c++14 -Wall -Werror=return-type -Werror=uninitialized -Wno-sign-compare -c -o state.o state.cpp state.cpp:65:12: error: no member named 'stDev' in 'State'; did you mean simply 'stDev'? return State::stDev(weeks, numberOfDataPoints); ^~~~~~~~~~~~ stDev ./stats.hpp:5:19: note: 'stDev' declared here static double stDev(WeekData* weeks, int count); ^ 1 error generated. make: *** [state.o] Error 1 make test-morbidity g++ -g -std=c++14 -Wall -Werror=return-type -Werror=uninitialized -Wno-sign-compare -c -o state.o state.cpp state.cpp:65:12: error: no member named 'stDev' in 'State'; did you mean simply 'stDev'? return State::stDev(weeks, numberOfDataPoints); ^~~~~~~~~~~~ stDev ./stats.hpp:5:19: note: 'stDev' declared here static double stDev(WeekData* weeks, int count);
  • 2. ^ 1 error generated. make: *** [state.o] Error 1 Code test-morbidity.cpp #include "catch/catch.hpp" #include "../morbidity.hpp" const std::string INVALID_STATE = "foo"; TEST_CASE("Testing Morbidity class") { Morbidity dataset; CHECK(!dataset.load("foo.bar")); CHECK(dataset.load("data.csv")); CHECK(Approx(-1.0) == dataset.getMean(INVALID_STATE)); CHECK(Approx(1036.78).epsilon(0.01) == dataset.getMean("Alabama")); CHECK(Approx(81.17).epsilon(0.01) == dataset.getMean("Alaska")); CHECK(16 == dataset.getStateOutlierCount("Alabama")); auto outliers = dataset.getStateOutliers("Alabama"); CHECK("2020-07-25 - total deaths: 1333" == outliers.at(0)); CHECK("2021-02-06 - total deaths: 1503" == outliers.at(12)); CHECK_THAT(dataset.getOutlierInfoForAllStates(), Catch::Contains("West Virginia: 19")); } test-state.cpp #include
  • 3. #include "../state.hpp" #include "catch/catch.hpp" TEST_CASE("Testing State class on calculation") { State bama("Alabama"); CHECK("Alabama" == bama.getName()); bama.addWeek("2020-05-02,2000"); bama.addWeek("2020-05-09,2000"); bama.addWeek("2020-05-16,100"); bama.addWeek("2020-05-23,2000"); bama.addWeek("2020-05-30,2000"); bama.addWeek("2020-06-06,2000"); CHECK(Approx(1683.33).epsilon(0.01) == bama.getMeanDeaths()); CHECK(Approx(708.08).epsilon(0.01) == bama.getStDev()); CHECK(1 == bama.getOutlierCount()); auto outliers = bama.getOutlierInfos(); CHECK("2020-05-16 - total deaths: 100" == outliers.at(0)); } TEST_CASE("Testing State class on rule of three") { State bama("Alabama"); CHECK("Alabama" == bama.getName()); State bama1(bama); CHECK("Alabama" == bama1.getName()); State bama2; bama2 = bama;
  • 4. CHECK("Alabama" == bama2.getName()); } test-stats.cpp #include "catch/catch.hpp" #include "../stats.hpp" #include "../week-data.hpp" WeekData data[] = { WeekData("1776-07-04,1"), // Just some static test data. WeekData("1776-07-11,2"), // The dates are not important WeekData("1776-07-18,3"), // since we are just trying to test the WeekData("1776-07-25,5"), // statistical calculations WeekData("1776-08-02,6") }; TEST_CASE("Testing Mean") { // Comparing doubles, can use Approx() to allow some epsilon difference CHECK(Approx(3.4) == getMean(data, 5)); } TEST_CASE("Testing Stdev") { CHECK(Approx(1.85).epsilon(0.01) == stDev(data, 5)); } TEST_CASE("Testing empty list") { // let's call the getMean of no numbers: 0 CHECK(Approx(0) == getMean({}, 0)); CHECK(Approx(0) == stDev({}, 0));
  • 5. } // Compile & run: // make clean test morbidity.cpp #include "morbidity.hpp" #include "state.hpp" #include #include Morbidity::Morbidity() : numberOfStates(0), states(nullptr) { } Morbidity::~Morbidity() { for (int i = 0; i < numberOfStates; i++) { delete states[i]; } delete[] states; } bool Morbidity::load(const std::string& filename) { std::ifstream file(filename); if (!file.is_open()) { return false; }
  • 6. std::string line; std::string stateName; while (std::getline(file, line)) { std::istringstream iss(line); std::string state, weekData; std::getline(iss, state, ','); std::getline(iss, weekData); if (state != stateName) { stateName = state; State* newState = new State(stateName); if (numberOfStates < 65) { if (states == nullptr) { states = new State*[65]; } states[numberOfStates] = newState; numberOfStates++; } } try { int deaths = std::stoi(weekData); if (states != nullptr) { states[numberOfStates - 1]->addWeek(weekData); } } catch (const std::invalid_argument& e) {
  • 7. } } file.close(); return true; } double Morbidity::getMean(const std::string& stateName) const { for (int i = 0; i < numberOfStates; i++) { if (states[i]->getName() == stateName) { return states[i]->getMeanDeaths(); } } return -1.0; } int Morbidity::getStateOutlierCount(const std::string& stateName) const { for (int i = 0; i < numberOfStates; i++) { if (states[i]->getName() == stateName) { return states[i]->getOutlierCount(); } } return 0; } std::vector Morbidity::getStateOutliers(const std::string& stateName) const { for (int i = 0; i < numberOfStates; i++) { if (states[i]->getName() == stateName) { return states[i]->getOutlierInfos();
  • 8. } } return std::vector(); } std::string Morbidity::getOutlierInfoForAllStates() const { std::string outlierInfo; for (int i = 0; i < numberOfStates; i++) { outlierInfo += states[i]->getName() + ": " + std::to_string(states[i]->getOutlierCount()) + " outlying weeksn"; } return outlierInfo; } morbidity.hpp #ifndef MORBIDITY_HPP #define MORBIDITY_HPP #include #include class State; class Morbidity { public: Morbidity(); ~Morbidity();
  • 9. bool load(const std::string& filename); double getMean(const std::string& stateName) const; int getStateOutlierCount(const std::string& stateName) const; std::vector getStateOutliers(const std::string& stateName) const; std::string getOutlierInfoForAllStates() const; private: int numberOfStates; State** states; }; #endif state.cpp #include "state.hpp" #include "week-data.hpp" #include "stats.hpp" State::State() : name(""), weeks(nullptr), numberOfDataPoints(0) { // Default constructor } State::State(std::string name) : name(name), numberOfDataPoints(0) { // Constructor with a name weeks = new WeekData[500]; // Assuming a maximum of 500 data points } State::State(const State& rhs) : name(rhs.name), numberOfDataPoints(rhs.numberOfDataPoints) { // Copy constructor weeks = new WeekData[500];
  • 10. for (int i = 0; i < numberOfDataPoints; i++) { weeks[i] = rhs.weeks[i]; } } State& State::operator=(const State& rhs) { // Assignment operator if (this == &rhs) { return *this; } name = rhs.name; numberOfDataPoints = rhs.numberOfDataPoints; if (weeks) { delete[] weeks; } weeks = new WeekData[500]; for (int i = 0; i < numberOfDataPoints; i++) { weeks[i] = rhs.weeks[i]; } return *this; } State::~State() { // Destructor delete[] weeks; }
  • 11. std::string State::getName() const { return name; } void State::addWeek(std::string weekData) { // Implement function to add week data if (numberOfDataPoints < 500) { weeks[numberOfDataPoints] = WeekData(weekData); numberOfDataPoints++; } } double State::getMeanDeaths() const { return /*State::*/getMean(weeks, numberOfDataPoints); } double State::getStDev() const { return State::stDev(weeks, numberOfDataPoints); } int State::getOutlierCount() const { int outlierCount = 0; double mean = getMeanDeaths(); double stDeviation = getStDev(); for (int i = 0; i < numberOfDataPoints; i++) { if (std::abs(weeks[i].getDeathCount() - mean) > 2 * stDeviation) { outlierCount++; }
  • 12. } return outlierCount; } std::vector State::getOutlierInfos() const { std::vector outlierInfos; double mean = getMeanDeaths(); double stDeviation = getStDev(); for (int i = 0; i < numberOfDataPoints; i++) { if (std::abs(weeks[i].getDeathCount() - mean) > 2 * stDeviation) { outlierInfos.push_back(weeks[i].info()); } } return outlierInfos; } state.hpp #ifndef STATE_HPP #define STATE_HPP #include #include class WeekData; class State { public:
  • 13. State(); State(std::string name); State(const State& rhs); State& operator=(const State& rhs); ~State(); std::string getName() const; void addWeek(std::string weekData); double getMeanDeaths() const; double getStDev() const; int getOutlierCount() const; std::vector getOutlierInfos() const; private: std::string name; WeekData* weeks; int numberOfDataPoints; }; #endif stats.cpp #include "stats.hpp" #include "week-data.hpp" #include double /*Stats::*/getMean(WeekData* weeks, int count) { double sum = 0.0; for (int i = 0; i < count; i++) { sum += weeks[i].getDeathCount(); } return sum / count; }
  • 14. double /*Stats::*/stDev(WeekData* weeks, int count) { double mean = getMean(weeks, count); double sumSquaredDiffs = 0.0; for (int i = 0; i < count; i++) { double diff = weeks[i].getDeathCount() - mean; sumSquaredDiffs += diff * diff; } double variance = sumSquaredDiffs / count; return std::sqrt(variance); } stats.hpp #ifndef STATS_HPP #define STATS_HPP #include "week-data.hpp" static double getMean(WeekData* weeks, int count); static double stDev(WeekData* weeks, int count); #endif