SlideShare a Scribd company logo
1 of 13
Download to read offline
Baby names and birth weights”
Introduction
Babies are weighed soon after birth and this birth weight is recorded as part of a baby’s medical
record. A low birth weight indicates increased risk for complications and such babies are given
specialized care until they gain weight. Public health agencies, such as the Centers for Disease
Control and Prevention (CDC) in the United States, keep records of births and birth weights. In
this project you will write principled object-oriented C++ code to read a data file recording birth
information and answer questions based on this data.
Objective
You are given data in text files - each line in a text file is a baby girl’s first name followed by her
birth weight in grams (an integer). The text file could contain a large number of such lines. Write
code to answer the following questions:
How many births are recorded in the data file?
How many babies have a given first name?
How many babies are born with a low birth weight (less than 2,500 grams)?
Which baby name is the most popular?
The code
You are given “skeleton” code with many blank spaces. Your assignment is to fill in the missing
parts so that the code is complete and works properly. The code is in three files:
main.cpp contains the main function and a set of unit tests, implemented using assert statements -
each assert statement compares the output of your code with the expected correct answer. Since
the provided code is only a template, all the tests will fail immediately with runtime errors. As
you add functionality and fix any bugs that may arise, the tests will be able to get further and
further. Donotedit this main.cpp file.
Baby.h contains code for a “Baby” data class. This class is incomplete and you should complete
it.
MedicalRecord.h contains a class whose methods can return answers to the questions asked in
this project. You can use (dynamic) arrays but not any of the STL containers (such as
std::vector). This class is incomplete and you should complete it.
Hints
MedicalRecord.h will require the use of an array-based data structure of Baby objects. Note that
private data members are also incomplete. Feel free to add private member variables to both
MedicalRecord.h and Baby.h as you need. There is more than one way to solve this problem!
Baby.h (I already completed this portion)
#pragma once
#include
using namespace std;
// class that contains information related to a single birth or baby name
class Baby {
public:
Baby() { // default constructor
};
Baby(string s, int w)
{
name = s;
weight = w;
}
// a "getter" method
int getWeight() {
return weight;
}
// a "getter" method
string getName() {
return name;
}
private:
string name;
int weight;
};
MedicalRecord.h (Please answer each line that says “To be completed” and explain thoroughly
on how to add two text files into this header)
#pragma once
#include
#include
#include "Baby.h"
using namespace std;
class MedicalRecord {
public:
// default constructor
MedicalRecord() {
// TO BE COMPLETED
}
// destructor
~MedicalRecord() {
// TO BE COMPLETED
}
// Load information from a text file with the given filename.
void buildMedicalRecordfromDatafile(string filename) {
ifstream myfile(filename);
if (myfile.is_open()) {
cout << "Successfully opened file " << filename << endl;
string name;
int weight;
while (myfile >> name >> weight) {
// cout << name << " " << weight << endl;
Baby b(name, weight);
addEntry(b);
}
myfile.close();
}
else
throw invalid_argument("Could not open file " + filename);
}
// return the most frequently appearing name in the text file
string mostPopularName() {
return "COMPLETE ME"; // TO BE COMPLETED
}
// return the number of baby records loaded from the text file
int numberOfBirths() {
return -1; // TO BE COMPLETED
}
// return the number of babies who had birth weight < 2500 grams
int numberOfBabiesWithLowBirthWeight() {
return -1; // TO BE COMPLETED
}
// return the number of babies who have the name contained in string s
int numberOfBabiesWithName(string s) {
return -1; // TO BE COMPLETED
}
private:
// update the data structure with information contained in Baby object
void addEntry(Baby b) {
// TO BE COMPLETED
}
// Add private member variables for your data structure along with any
// other variables required to implement the public member functions
}
baby_data_large.txt
https://raw.githubusercontent.com/CSUF-Computer-Science/spring2017-project-1-cpsc-131-
section-01-
1/master/baby_data_large.txt?token=AYoWp6P6aphlDMGV7S8o7ZMnKQfA_4psks5Ys0jcwA
%3D%3D
baby_data_small.txt
Sophia 4435
Emma 3561
Ava 2918
Sophia 3765
Mia 2204
Sophia 2749
Lourdes 3981
Sophia 2617
Olivia 4352
Emma 840
Main.cpp (Do not edit)
#include
#include
#include
#include
#include "MedicalRecord.h"
#include "Baby.h"
using namespace std;
int main() {
try {
{
// test only the Baby class
Baby babyTest("Testname", 1000);
assert(babyTest.getName() == "Testname");
assert(babyTest.getWeight() == 1000);
}
{ // test full code with a small data file
MedicalRecord MR;
MR.buildMedicalRecordfromDatafile("baby_data_small.txt"); // build a medical
record from the file of baby names and weights
int nBirths = MR.numberOfBirths();
cout << "Number of births: " << nBirths << endl;
assert(nBirths == 10);
int nEmma = MR.numberOfBabiesWithName("Emma");
cout << "Number of babies with name Emma: " << nEmma << endl;
assert(nEmma == 2);
int nLow = MR.numberOfBabiesWithLowBirthWeight();
cout << "Number of babies with low birth weight: " << nLow << endl;
assert(nLow == 2);
string mostPopularName = MR.mostPopularName();
cout << "Most popular baby name: " << mostPopularName << endl;
assert (mostPopularName == "Sophia");
}
{ // test full code with a large data file
MedicalRecord MR;
MR.buildMedicalRecordfromDatafile("baby_data_large.txt"); // build a medical
record from the file of baby names and weights
int nBirths = MR.numberOfBirths();
cout << "Number of births: " << nBirths << endl;
assert (nBirths == 199604);
int nEva = MR.numberOfBabiesWithName("Eva");
cout << "Number of babies with name Eva: " << nEva << endl;
assert (nEva == 566);
int nLow = MR.numberOfBabiesWithLowBirthWeight();
cout << "Number of babies with low birth weight: " << nLow << endl;
assert (nLow == 15980);
string mostPopularName = MR.mostPopularName();
cout << "Most popular baby name: " << mostPopularName << endl;
assert (mostPopularName == "Emma");
}
}
catch (exception &e) {
cout << e.what() << endl;
}
// system("pause");
}
#pragma once
#include
#include
#include "Baby.h"
using namespace std;
class MedicalRecord {
public:
// default constructor
MedicalRecord() {
// TO BE COMPLETED
}
// destructor
~MedicalRecord() {
// TO BE COMPLETED
}
// Load information from a text file with the given filename.
void buildMedicalRecordfromDatafile(string filename) {
ifstream myfile(filename);
if (myfile.is_open()) {
cout << "Successfully opened file " << filename << endl;
string name;
int weight;
while (myfile >> name >> weight) {
// cout << name << " " << weight << endl;
Baby b(name, weight);
addEntry(b);
}
myfile.close();
}
else
throw invalid_argument("Could not open file " + filename);
}
// return the most frequently appearing name in the text file
string mostPopularName() {
return "COMPLETE ME"; // TO BE COMPLETED
}
// return the number of baby records loaded from the text file
int numberOfBirths() {
return -1; // TO BE COMPLETED
}
// return the number of babies who had birth weight < 2500 grams
int numberOfBabiesWithLowBirthWeight() {
return -1; // TO BE COMPLETED
}
// return the number of babies who have the name contained in string s
int numberOfBabiesWithName(string s) {
return -1; // TO BE COMPLETED
}
private:
// update the data structure with information contained in Baby object
void addEntry(Baby b) {
// TO BE COMPLETED
}
// Add private member variables for your data structure along with any
// other variables required to implement the public member functions
}
baby_data_large.txt
https://raw.githubusercontent.com/CSUF-Computer-Science/spring2017-project-1-cpsc-131-
section-01-
1/master/baby_data_large.txt?token=AYoWp6P6aphlDMGV7S8o7ZMnKQfA_4psks5Ys0jcwA
%3D%3D
baby_data_small.txt
Sophia 4435
Emma 3561
Ava 2918
Sophia 3765
Mia 2204
Sophia 2749
Lourdes 3981
Sophia 2617
Olivia 4352
Emma 840
Main.cpp (Do not edit)
#include
#include
#include
#include
#include "MedicalRecord.h"
#include "Baby.h"
using namespace std;
int main() {
try {
{
// test only the Baby class
Baby babyTest("Testname", 1000);
assert(babyTest.getName() == "Testname");
assert(babyTest.getWeight() == 1000);
}
{ // test full code with a small data file
MedicalRecord MR;
MR.buildMedicalRecordfromDatafile("baby_data_small.txt"); // build a
medical record from the file of baby names and weights
int nBirths = MR.numberOfBirths();
cout << "Number of births: " << nBirths << endl;
assert(nBirths == 10);
int nEmma = MR.numberOfBabiesWithName("Emma");
cout << "Number of babies with name Emma: " << nEmma << endl;
assert(nEmma == 2);
int nLow = MR.numberOfBabiesWithLowBirthWeight();
cout << "Number of babies with low birth weight: " << nLow << endl;
assert(nLow == 2);
string mostPopularName = MR.mostPopularName();
cout << "Most popular baby name: " << mostPopularName << endl;
assert (mostPopularName == "Sophia");
}
{ // test full code with a large data file
MedicalRecord MR;
MR.buildMedicalRecordfromDatafile("baby_data_large.txt"); // build a medical
record from the file of baby names and weights
int nBirths = MR.numberOfBirths();
cout << "Number of births: " << nBirths << endl;
assert (nBirths == 199604);
int nEva = MR.numberOfBabiesWithName("Eva");
cout << "Number of babies with name Eva: " << nEva << endl;
assert (nEva == 566);
int nLow = MR.numberOfBabiesWithLowBirthWeight();
cout << "Number of babies with low birth weight: " << nLow << endl;
assert (nLow == 15980);
string mostPopularName = MR.mostPopularName();
cout << "Most popular baby name: " << mostPopularName << endl;
assert (mostPopularName == "Emma");
}
}
catch (exception &e) {
cout << e.what() << endl;
}
// system("pause");
}
Solution
#include
#include
#include
#include
#include "MedicalRecord.h"
#include "Baby.h"
using namespace std;
int main() {
try {
{
// test only the Baby class
Baby babyTest("Testname", 1000);
assert(babyTest.getName() == "Testname");
assert(babyTest.getWeight() == 1000);
}
{ // test full code with a small data file
MedicalRecord MR;
MR.buildMedicalRecordfromDatafile("baby_data_small.txt"); // build a medical
record from the file of baby names and weights
int nBirths = MR.numberOfBirths();
cout << "Number of births: " << nBirths << endl;
assert(nBirths == 10);
int nEmma = MR.numberOfBabiesWithName("Emma");
cout << "Number of babies with name Emma: " << nEmma << endl;
assert(nEmma == 2);
int nLow = MR.numberOfBabiesWithLowBirthWeight();
cout << "Number of babies with low birth weight: " << nLow << endl;
assert(nLow == 2);
string mostPopularName = MR.mostPopularName();
cout << "Most popular baby name: " << mostPopularName << endl;
assert (mostPopularName == "Sophia");
}
{ // test full code with a large data file
MedicalRecord MR;
MR.buildMedicalRecordfromDatafile("baby_data_large.txt"); // build a medical
record from the file of baby names and weights
int nBirths = MR.numberOfBirths();
cout << "Number of births: " << nBirths << endl;
assert (nBirths == 199604);
int nEva = MR.numberOfBabiesWithName("Eva");
cout << "Number of babies with name Eva: " << nEva << endl;
assert (nEva == 566);
int nLow = MR.numberOfBabiesWithLowBirthWeight();
cout << "Number of babies with low birth weight: " << nLow << endl;
assert (nLow == 15980);
string mostPopularName = MR.mostPopularName();
cout << "Most popular baby name: " << mostPopularName << endl;
assert (mostPopularName == "Emma");
}
}
catch (exception &e) {
cout << e.what() << endl;
}
// system("pause");
}
#include
#include
#include
#include
#include "MedicalRecord.h"
#include "Baby.h"
using namespace std;
int main() {
try {
{
// test only the Baby class
Baby babyTest("Testname", 1000);
assert(babyTest.getName() == "Testname");
assert(babyTest.getWeight() == 1000);
}
{ // test full code with a small data file
MedicalRecord MR;
MR.buildMedicalRecordfromDatafile("baby_data_small.txt"); // build a
medical record from the file of baby names and weights
int nBirths = MR.numberOfBirths();
cout << "Number of births: " << nBirths << endl;
assert(nBirths == 10);
int nEmma = MR.numberOfBabiesWithName("Emma");
cout << "Number of babies with name Emma: " << nEmma << endl;
assert(nEmma == 2);
int nLow = MR.numberOfBabiesWithLowBirthWeight();
cout << "Number of babies with low birth weight: " << nLow << endl;
assert(nLow == 2);
string mostPopularName = MR.mostPopularName();
cout << "Most popular baby name: " << mostPopularName << endl;
assert (mostPopularName == "Sophia");
}
{ // test full code with a large data file
MedicalRecord MR;
MR.buildMedicalRecordfromDatafile("baby_data_large.txt"); // build a medical
record from the file of baby names and weights
int nBirths = MR.numberOfBirths();
cout << "Number of births: " << nBirths << endl;
assert (nBirths == 199604);
int nEva = MR.numberOfBabiesWithName("Eva");
cout << "Number of babies with name Eva: " << nEva << endl;
assert (nEva == 566);
int nLow = MR.numberOfBabiesWithLowBirthWeight();
cout << "Number of babies with low birth weight: " << nLow << endl;
assert (nLow == 15980);
string mostPopularName = MR.mostPopularName();
cout << "Most popular baby name: " << mostPopularName << endl;
assert (mostPopularName == "Emma");
}
}
catch (exception &e) {
cout << e.what() << endl;
}
// system("pause");
}

More Related Content

Similar to Baby names and birth weights”IntroductionBabies are weighed soon.pdf

This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
jillisacebi75827
 
How do I get Main-java to compile- the program is incomplete - Need.docx
How do I get Main-java to compile- the program is  incomplete -  Need.docxHow do I get Main-java to compile- the program is  incomplete -  Need.docx
How do I get Main-java to compile- the program is incomplete - Need.docx
Juliang56Parsonso
 
Brinkley – Over HereChanges during WWII led to an .docx
Brinkley – Over HereChanges during WWII led to an .docxBrinkley – Over HereChanges during WWII led to an .docx
Brinkley – Over HereChanges during WWII led to an .docx
AASTHA76
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
Nicholas Zakas
 
CS 649 Database Management Systems Fall 2017 Instructor.docx
CS 649 Database  Management Systems  Fall 2017  Instructor.docxCS 649 Database  Management Systems  Fall 2017  Instructor.docx
CS 649 Database Management Systems Fall 2017 Instructor.docx
annettsparrow
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
amoffat
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
guestc38d4b
 
Google.Test4prep.Professional-Data-Engineer.v2038q.pdf
Google.Test4prep.Professional-Data-Engineer.v2038q.pdfGoogle.Test4prep.Professional-Data-Engineer.v2038q.pdf
Google.Test4prep.Professional-Data-Engineer.v2038q.pdf
ssuser22b701
 
Android Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdfAndroid Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdf
feelinggift
 
Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry university
lhkslkdh89009
 

Similar to Baby names and birth weights”IntroductionBabies are weighed soon.pdf (20)

Google guava
Google guavaGoogle guava
Google guava
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
 
An Overview of Entity Framework
An Overview of Entity FrameworkAn Overview of Entity Framework
An Overview of Entity Framework
 
How to separate the f2 e and sde in web development for_taobao
How to separate the f2 e and sde in web development for_taobaoHow to separate the f2 e and sde in web development for_taobao
How to separate the f2 e and sde in web development for_taobao
 
How do I get Main-java to compile- the program is incomplete - Need.docx
How do I get Main-java to compile- the program is  incomplete -  Need.docxHow do I get Main-java to compile- the program is  incomplete -  Need.docx
How do I get Main-java to compile- the program is incomplete - Need.docx
 
My Portfolio
My PortfolioMy Portfolio
My Portfolio
 
Brinkley – Over HereChanges during WWII led to an .docx
Brinkley – Over HereChanges during WWII led to an .docxBrinkley – Over HereChanges during WWII led to an .docx
Brinkley – Over HereChanges during WWII led to an .docx
 
Merrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
Merrill's Journey to CI-CD and Continuous Testing by Ashish MukherjeeMerrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
Merrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
 
CS 649 Database Management Systems Fall 2017 Instructor.docx
CS 649 Database  Management Systems  Fall 2017  Instructor.docxCS 649 Database  Management Systems  Fall 2017  Instructor.docx
CS 649 Database Management Systems Fall 2017 Instructor.docx
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Google.Test4prep.Professional-Data-Engineer.v2038q.pdf
Google.Test4prep.Professional-Data-Engineer.v2038q.pdfGoogle.Test4prep.Professional-Data-Engineer.v2038q.pdf
Google.Test4prep.Professional-Data-Engineer.v2038q.pdf
 
Clean Code
Clean CodeClean Code
Clean Code
 
My Portfolio
My PortfolioMy Portfolio
My Portfolio
 
Android Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdfAndroid Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdf
 
Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry university
 

More from fathimaoptical

Compare naive, effector, and memory T & B cells (survival time, Ig &.pdf
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdfCompare naive, effector, and memory T & B cells (survival time, Ig &.pdf
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdf
fathimaoptical
 
Choose one of the evolutions of CIT and discuss how it may have made.pdf
Choose one of the evolutions of CIT and discuss how it may have made.pdfChoose one of the evolutions of CIT and discuss how it may have made.pdf
Choose one of the evolutions of CIT and discuss how it may have made.pdf
fathimaoptical
 
Without the effects of cyanobacteria or algae on lichen metabolism, .pdf
Without the effects of cyanobacteria or algae on lichen metabolism, .pdfWithout the effects of cyanobacteria or algae on lichen metabolism, .pdf
Without the effects of cyanobacteria or algae on lichen metabolism, .pdf
fathimaoptical
 
Question How can I called this method in the main, and how can I .pdf
Question How can I called this method in the main, and how can I .pdfQuestion How can I called this method in the main, and how can I .pdf
Question How can I called this method in the main, and how can I .pdf
fathimaoptical
 
Question 1. List and describe three rules of natural justice, provid.pdf
Question 1. List and describe three rules of natural justice, provid.pdfQuestion 1. List and describe three rules of natural justice, provid.pdf
Question 1. List and describe three rules of natural justice, provid.pdf
fathimaoptical
 
Modify this code to do an Insert function for an AVL tree, instead o.pdf
Modify this code to do an Insert function for an AVL tree, instead o.pdfModify this code to do an Insert function for an AVL tree, instead o.pdf
Modify this code to do an Insert function for an AVL tree, instead o.pdf
fathimaoptical
 

More from fathimaoptical (20)

Define a knowledge-based agent, and describe its major components. W.pdf
Define a knowledge-based agent, and describe its major components. W.pdfDefine a knowledge-based agent, and describe its major components. W.pdf
Define a knowledge-based agent, and describe its major components. W.pdf
 
Create a function mean comp that compares the mean value of the odd n.pdf
Create a function mean comp that compares the mean value of the odd n.pdfCreate a function mean comp that compares the mean value of the odd n.pdf
Create a function mean comp that compares the mean value of the odd n.pdf
 
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdf
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdfCompare naive, effector, and memory T & B cells (survival time, Ig &.pdf
Compare naive, effector, and memory T & B cells (survival time, Ig &.pdf
 
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdf
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdfConsider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdf
Consider the titration of50.0 mL of 0.217 M hydrazoic acid (HN3, Ka=.pdf
 
Choose one of the evolutions of CIT and discuss how it may have made.pdf
Choose one of the evolutions of CIT and discuss how it may have made.pdfChoose one of the evolutions of CIT and discuss how it may have made.pdf
Choose one of the evolutions of CIT and discuss how it may have made.pdf
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
Without the effects of cyanobacteria or algae on lichen metabolism, .pdf
Without the effects of cyanobacteria or algae on lichen metabolism, .pdfWithout the effects of cyanobacteria or algae on lichen metabolism, .pdf
Without the effects of cyanobacteria or algae on lichen metabolism, .pdf
 
What is this image trying to tell you about the American West.pdf
What is this image trying to tell you about the American West.pdfWhat is this image trying to tell you about the American West.pdf
What is this image trying to tell you about the American West.pdf
 
What is the difference between a defined-benefit and a defined-contr.pdf
What is the difference between a defined-benefit and a defined-contr.pdfWhat is the difference between a defined-benefit and a defined-contr.pdf
What is the difference between a defined-benefit and a defined-contr.pdf
 
This is question about excel cuers.How would you use Financial Fun.pdf
This is question about excel cuers.How would you use Financial Fun.pdfThis is question about excel cuers.How would you use Financial Fun.pdf
This is question about excel cuers.How would you use Financial Fun.pdf
 
The surface area to volume ration is least improtant in thea. sink.pdf
The surface area to volume ration is least improtant in thea. sink.pdfThe surface area to volume ration is least improtant in thea. sink.pdf
The surface area to volume ration is least improtant in thea. sink.pdf
 
The Martian calendar has sixteen months instead of twelve. What is t.pdf
The Martian calendar has sixteen months instead of twelve. What is t.pdfThe Martian calendar has sixteen months instead of twelve. What is t.pdf
The Martian calendar has sixteen months instead of twelve. What is t.pdf
 
Question How can I called this method in the main, and how can I .pdf
Question How can I called this method in the main, and how can I .pdfQuestion How can I called this method in the main, and how can I .pdf
Question How can I called this method in the main, and how can I .pdf
 
Question 1. List and describe three rules of natural justice, provid.pdf
Question 1. List and describe three rules of natural justice, provid.pdfQuestion 1. List and describe three rules of natural justice, provid.pdf
Question 1. List and describe three rules of natural justice, provid.pdf
 
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdf
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdfPostal ClerkAssistant. Why do the five steps of the recruitment pro.pdf
Postal ClerkAssistant. Why do the five steps of the recruitment pro.pdf
 
OverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdfOverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdf
 
Negotiation - Porto (Porto case).note this is a case study so the.pdf
Negotiation - Porto (Porto case).note this is a case study so the.pdfNegotiation - Porto (Porto case).note this is a case study so the.pdf
Negotiation - Porto (Porto case).note this is a case study so the.pdf
 
need help with my computer science lab assignemnt. this assignment i.pdf
need help with my computer science lab assignemnt. this assignment i.pdfneed help with my computer science lab assignemnt. this assignment i.pdf
need help with my computer science lab assignemnt. this assignment i.pdf
 
Name a protein that contacts the insulin receptor inside the cell.pdf
Name a protein that contacts the insulin receptor inside the cell.pdfName a protein that contacts the insulin receptor inside the cell.pdf
Name a protein that contacts the insulin receptor inside the cell.pdf
 
Modify this code to do an Insert function for an AVL tree, instead o.pdf
Modify this code to do an Insert function for an AVL tree, instead o.pdfModify this code to do an Insert function for an AVL tree, instead o.pdf
Modify this code to do an Insert function for an AVL tree, instead o.pdf
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Recently uploaded (20)

Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Baby names and birth weights”IntroductionBabies are weighed soon.pdf

  • 1. Baby names and birth weights” Introduction Babies are weighed soon after birth and this birth weight is recorded as part of a baby’s medical record. A low birth weight indicates increased risk for complications and such babies are given specialized care until they gain weight. Public health agencies, such as the Centers for Disease Control and Prevention (CDC) in the United States, keep records of births and birth weights. In this project you will write principled object-oriented C++ code to read a data file recording birth information and answer questions based on this data. Objective You are given data in text files - each line in a text file is a baby girl’s first name followed by her birth weight in grams (an integer). The text file could contain a large number of such lines. Write code to answer the following questions: How many births are recorded in the data file? How many babies have a given first name? How many babies are born with a low birth weight (less than 2,500 grams)? Which baby name is the most popular? The code You are given “skeleton” code with many blank spaces. Your assignment is to fill in the missing parts so that the code is complete and works properly. The code is in three files: main.cpp contains the main function and a set of unit tests, implemented using assert statements - each assert statement compares the output of your code with the expected correct answer. Since the provided code is only a template, all the tests will fail immediately with runtime errors. As you add functionality and fix any bugs that may arise, the tests will be able to get further and further. Donotedit this main.cpp file. Baby.h contains code for a “Baby” data class. This class is incomplete and you should complete it. MedicalRecord.h contains a class whose methods can return answers to the questions asked in this project. You can use (dynamic) arrays but not any of the STL containers (such as std::vector). This class is incomplete and you should complete it. Hints MedicalRecord.h will require the use of an array-based data structure of Baby objects. Note that private data members are also incomplete. Feel free to add private member variables to both MedicalRecord.h and Baby.h as you need. There is more than one way to solve this problem! Baby.h (I already completed this portion) #pragma once
  • 2. #include using namespace std; // class that contains information related to a single birth or baby name class Baby { public: Baby() { // default constructor }; Baby(string s, int w) { name = s; weight = w; } // a "getter" method int getWeight() { return weight; } // a "getter" method string getName() { return name; } private: string name; int weight; }; MedicalRecord.h (Please answer each line that says “To be completed” and explain thoroughly on how to add two text files into this header) #pragma once #include #include #include "Baby.h" using namespace std; class MedicalRecord { public: // default constructor
  • 3. MedicalRecord() { // TO BE COMPLETED } // destructor ~MedicalRecord() { // TO BE COMPLETED } // Load information from a text file with the given filename. void buildMedicalRecordfromDatafile(string filename) { ifstream myfile(filename); if (myfile.is_open()) { cout << "Successfully opened file " << filename << endl; string name; int weight; while (myfile >> name >> weight) { // cout << name << " " << weight << endl; Baby b(name, weight); addEntry(b); } myfile.close(); } else throw invalid_argument("Could not open file " + filename); } // return the most frequently appearing name in the text file string mostPopularName() { return "COMPLETE ME"; // TO BE COMPLETED } // return the number of baby records loaded from the text file int numberOfBirths() { return -1; // TO BE COMPLETED } // return the number of babies who had birth weight < 2500 grams int numberOfBabiesWithLowBirthWeight() { return -1; // TO BE COMPLETED }
  • 4. // return the number of babies who have the name contained in string s int numberOfBabiesWithName(string s) { return -1; // TO BE COMPLETED } private: // update the data structure with information contained in Baby object void addEntry(Baby b) { // TO BE COMPLETED } // Add private member variables for your data structure along with any // other variables required to implement the public member functions } baby_data_large.txt https://raw.githubusercontent.com/CSUF-Computer-Science/spring2017-project-1-cpsc-131- section-01- 1/master/baby_data_large.txt?token=AYoWp6P6aphlDMGV7S8o7ZMnKQfA_4psks5Ys0jcwA %3D%3D baby_data_small.txt Sophia 4435 Emma 3561 Ava 2918 Sophia 3765 Mia 2204 Sophia 2749 Lourdes 3981 Sophia 2617 Olivia 4352 Emma 840 Main.cpp (Do not edit) #include #include #include #include #include "MedicalRecord.h" #include "Baby.h" using namespace std;
  • 5. int main() { try { { // test only the Baby class Baby babyTest("Testname", 1000); assert(babyTest.getName() == "Testname"); assert(babyTest.getWeight() == 1000); } { // test full code with a small data file MedicalRecord MR; MR.buildMedicalRecordfromDatafile("baby_data_small.txt"); // build a medical record from the file of baby names and weights int nBirths = MR.numberOfBirths(); cout << "Number of births: " << nBirths << endl; assert(nBirths == 10); int nEmma = MR.numberOfBabiesWithName("Emma"); cout << "Number of babies with name Emma: " << nEmma << endl; assert(nEmma == 2); int nLow = MR.numberOfBabiesWithLowBirthWeight(); cout << "Number of babies with low birth weight: " << nLow << endl; assert(nLow == 2); string mostPopularName = MR.mostPopularName(); cout << "Most popular baby name: " << mostPopularName << endl; assert (mostPopularName == "Sophia"); } { // test full code with a large data file MedicalRecord MR; MR.buildMedicalRecordfromDatafile("baby_data_large.txt"); // build a medical record from the file of baby names and weights int nBirths = MR.numberOfBirths(); cout << "Number of births: " << nBirths << endl; assert (nBirths == 199604); int nEva = MR.numberOfBabiesWithName("Eva"); cout << "Number of babies with name Eva: " << nEva << endl; assert (nEva == 566); int nLow = MR.numberOfBabiesWithLowBirthWeight();
  • 6. cout << "Number of babies with low birth weight: " << nLow << endl; assert (nLow == 15980); string mostPopularName = MR.mostPopularName(); cout << "Most popular baby name: " << mostPopularName << endl; assert (mostPopularName == "Emma"); } } catch (exception &e) { cout << e.what() << endl; } // system("pause"); } #pragma once #include #include #include "Baby.h" using namespace std; class MedicalRecord { public: // default constructor MedicalRecord() { // TO BE COMPLETED } // destructor ~MedicalRecord() { // TO BE COMPLETED } // Load information from a text file with the given filename. void buildMedicalRecordfromDatafile(string filename) { ifstream myfile(filename); if (myfile.is_open()) { cout << "Successfully opened file " << filename << endl; string name; int weight; while (myfile >> name >> weight) { // cout << name << " " << weight << endl;
  • 7. Baby b(name, weight); addEntry(b); } myfile.close(); } else throw invalid_argument("Could not open file " + filename); } // return the most frequently appearing name in the text file string mostPopularName() { return "COMPLETE ME"; // TO BE COMPLETED } // return the number of baby records loaded from the text file int numberOfBirths() { return -1; // TO BE COMPLETED } // return the number of babies who had birth weight < 2500 grams int numberOfBabiesWithLowBirthWeight() { return -1; // TO BE COMPLETED } // return the number of babies who have the name contained in string s int numberOfBabiesWithName(string s) { return -1; // TO BE COMPLETED } private: // update the data structure with information contained in Baby object void addEntry(Baby b) { // TO BE COMPLETED } // Add private member variables for your data structure along with any // other variables required to implement the public member functions } baby_data_large.txt https://raw.githubusercontent.com/CSUF-Computer-Science/spring2017-project-1-cpsc-131- section-01- 1/master/baby_data_large.txt?token=AYoWp6P6aphlDMGV7S8o7ZMnKQfA_4psks5Ys0jcwA
  • 8. %3D%3D baby_data_small.txt Sophia 4435 Emma 3561 Ava 2918 Sophia 3765 Mia 2204 Sophia 2749 Lourdes 3981 Sophia 2617 Olivia 4352 Emma 840 Main.cpp (Do not edit) #include #include #include #include #include "MedicalRecord.h" #include "Baby.h" using namespace std; int main() { try { { // test only the Baby class Baby babyTest("Testname", 1000); assert(babyTest.getName() == "Testname"); assert(babyTest.getWeight() == 1000); } { // test full code with a small data file MedicalRecord MR; MR.buildMedicalRecordfromDatafile("baby_data_small.txt"); // build a medical record from the file of baby names and weights int nBirths = MR.numberOfBirths(); cout << "Number of births: " << nBirths << endl; assert(nBirths == 10); int nEmma = MR.numberOfBabiesWithName("Emma");
  • 9. cout << "Number of babies with name Emma: " << nEmma << endl; assert(nEmma == 2); int nLow = MR.numberOfBabiesWithLowBirthWeight(); cout << "Number of babies with low birth weight: " << nLow << endl; assert(nLow == 2); string mostPopularName = MR.mostPopularName(); cout << "Most popular baby name: " << mostPopularName << endl; assert (mostPopularName == "Sophia"); } { // test full code with a large data file MedicalRecord MR; MR.buildMedicalRecordfromDatafile("baby_data_large.txt"); // build a medical record from the file of baby names and weights int nBirths = MR.numberOfBirths(); cout << "Number of births: " << nBirths << endl; assert (nBirths == 199604); int nEva = MR.numberOfBabiesWithName("Eva"); cout << "Number of babies with name Eva: " << nEva << endl; assert (nEva == 566); int nLow = MR.numberOfBabiesWithLowBirthWeight(); cout << "Number of babies with low birth weight: " << nLow << endl; assert (nLow == 15980); string mostPopularName = MR.mostPopularName(); cout << "Most popular baby name: " << mostPopularName << endl; assert (mostPopularName == "Emma"); } } catch (exception &e) { cout << e.what() << endl; } // system("pause"); } Solution #include
  • 10. #include #include #include #include "MedicalRecord.h" #include "Baby.h" using namespace std; int main() { try { { // test only the Baby class Baby babyTest("Testname", 1000); assert(babyTest.getName() == "Testname"); assert(babyTest.getWeight() == 1000); } { // test full code with a small data file MedicalRecord MR; MR.buildMedicalRecordfromDatafile("baby_data_small.txt"); // build a medical record from the file of baby names and weights int nBirths = MR.numberOfBirths(); cout << "Number of births: " << nBirths << endl; assert(nBirths == 10); int nEmma = MR.numberOfBabiesWithName("Emma"); cout << "Number of babies with name Emma: " << nEmma << endl; assert(nEmma == 2); int nLow = MR.numberOfBabiesWithLowBirthWeight(); cout << "Number of babies with low birth weight: " << nLow << endl; assert(nLow == 2); string mostPopularName = MR.mostPopularName(); cout << "Most popular baby name: " << mostPopularName << endl; assert (mostPopularName == "Sophia"); } { // test full code with a large data file MedicalRecord MR; MR.buildMedicalRecordfromDatafile("baby_data_large.txt"); // build a medical record from the file of baby names and weights int nBirths = MR.numberOfBirths();
  • 11. cout << "Number of births: " << nBirths << endl; assert (nBirths == 199604); int nEva = MR.numberOfBabiesWithName("Eva"); cout << "Number of babies with name Eva: " << nEva << endl; assert (nEva == 566); int nLow = MR.numberOfBabiesWithLowBirthWeight(); cout << "Number of babies with low birth weight: " << nLow << endl; assert (nLow == 15980); string mostPopularName = MR.mostPopularName(); cout << "Most popular baby name: " << mostPopularName << endl; assert (mostPopularName == "Emma"); } } catch (exception &e) { cout << e.what() << endl; } // system("pause"); } #include #include #include #include #include "MedicalRecord.h" #include "Baby.h" using namespace std; int main() { try { { // test only the Baby class Baby babyTest("Testname", 1000); assert(babyTest.getName() == "Testname"); assert(babyTest.getWeight() == 1000); } { // test full code with a small data file MedicalRecord MR; MR.buildMedicalRecordfromDatafile("baby_data_small.txt"); // build a
  • 12. medical record from the file of baby names and weights int nBirths = MR.numberOfBirths(); cout << "Number of births: " << nBirths << endl; assert(nBirths == 10); int nEmma = MR.numberOfBabiesWithName("Emma"); cout << "Number of babies with name Emma: " << nEmma << endl; assert(nEmma == 2); int nLow = MR.numberOfBabiesWithLowBirthWeight(); cout << "Number of babies with low birth weight: " << nLow << endl; assert(nLow == 2); string mostPopularName = MR.mostPopularName(); cout << "Most popular baby name: " << mostPopularName << endl; assert (mostPopularName == "Sophia"); } { // test full code with a large data file MedicalRecord MR; MR.buildMedicalRecordfromDatafile("baby_data_large.txt"); // build a medical record from the file of baby names and weights int nBirths = MR.numberOfBirths(); cout << "Number of births: " << nBirths << endl; assert (nBirths == 199604); int nEva = MR.numberOfBabiesWithName("Eva"); cout << "Number of babies with name Eva: " << nEva << endl; assert (nEva == 566); int nLow = MR.numberOfBabiesWithLowBirthWeight(); cout << "Number of babies with low birth weight: " << nLow << endl; assert (nLow == 15980); string mostPopularName = MR.mostPopularName(); cout << "Most popular baby name: " << mostPopularName << endl; assert (mostPopularName == "Emma"); } } catch (exception &e) { cout << e.what() << endl; } // system("pause");
  • 13. }