SlideShare a Scribd company logo
1 of 14
Download to read offline
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.pdfnageswara1958
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfChen-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++ codePVS-Studio LLC
 
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-optimizationsEgor Bogatov
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTsKevlin Henney
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsphanleson
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
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.pdfrushabhshah600
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019corehard_by
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer developmentAndrey 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.pdfsnewfashion
 
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.pdfsnewfashion
 
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.pdfsnewfashion
 
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.pdfsnewfashion
 
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.pdfsnewfashion
 
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.pdfsnewfashion
 
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.pdfsnewfashion
 
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.pdfsnewfashion
 
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.pdfsnewfashion
 

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

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

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