C++ homework project | Computer Science homework help

(1) Learn to create class structure in C++

(2) Create an array of objects in C++

(3) Search and perform operations on the array of objects

Project Description:

The input csv file for this project consists of rows of data that deals with COVID-19 cases and deaths per day for each county in every state in the United States. Here is an example,

date,county,state,fips,cases,deaths

2020-01-21,Snohomish,Washington,53061,1,0

2020-01-22,Snohomish,Washington,53061,1,0

2020-01-23,Snohomish,Washington,53061,1,0

For the purposes of this project, we will assume that the following are char* data types: date, county, and state. FIPS (unique identifier for each county) along with cases and deaths are int data types. Please note the comma delimiter in each row. You need ­­­to carefully read each field knowing that you will have a comma.

You will use redirected input (more later) to read an input txt file that contains the following:

counts  //number of data entries in the csv file

Filename.csv  //this is the file that contains the covid-19 data

Command  //details of what constitutes a command is given below

Command

Command

….

Your C++ program will read the counts value on the first line of the txt file, which represents the number of data entries in the csv file. (Note – the first line of the csv file contains descriptive variable fields, so there will be a total of [number of data entries + 1] lines in the csv file). Then, on the second line, it will read the Filename.csv and open the file for reading (more on how to do this in C++). After you open the file, you will read the data from each row of the csv file and create a COVID19 object. The COVID19 class is given below. You need to implement all of the necessary methods.

class COVID19 {

protected:

char* date;

char* county;

char* state;

int fips;

int cases;

int deaths;

public:

COVID19 (); //default constructor

COVID19 (char* da, char* co, char* s, int f, 

 int ca, int de); //initializer

display ();

//write all accessors and other methods as necessary

};

After your write the above class you will write the following class:

class COVID19DataSet {

protected:

COVID19* allData;

int count; //number of COVID19 objects in allData

int size; //maximum size of array

public:

COVID19DataSet (); //default constructor

COVID19DataSet (int initSize);

void display ();

void addRow (COVID19& oneData);

int findTotalCasesByCounty (char* county, char* state); 

int findTotalDeathsByCounty (char* county, char* state);

int findTotalCasesByState (char* state);

int findTotalDeathsByState (char* state); 

int findTotalCasesBySateWithDateRange (char* state,

char* startDate, char* endDate);

int findTotalDeathsBySateWithDateRange (char* state,

char* startDate, char* endDate);

~COVID19(); //destructor

//other methods as deem important

};

The structure of the main program will be something like this:

#include <iostream>

using namespace std;

// Write all the classes here

int main () {

int counts; // number of records in Filename.CSV

int command;

COVID19 oneRow;

//read the filename, for example, Filename.csv

//open the Filename.csv using fopen (google it for C++ to find out)

//assume that you named this file as myFile

//read the first integer in the file that contains the number of rows

//call this number counts

COVID19DataSet* myData = new COVID19DataSet (counts);

for (int i=0; i < counts; i++) {

//read the values in each row

//use setters to set the fields in oneRow

(*myData).addRow (oneRow);

} //end for loop

while (!cin.eof()) {

cin >> command;

switch (command) {

case 1: {

//read the rest of the row

(*myData).findTotalCasesByCounty (county, state);

break;

 }

case 2: {

 //do what is needed for command 2

 break;

 }

case 3: {

 //do what is needed for command 3

 break;

 }

case 4: {

 //do what is needed for command 4

 break;

 }

case 5: {

 //do what is needed for command 5

 break;

 }

case 6: {

 //do what is needed for command 6

 break;

 }

default: cout << “Wrong commandn”;

} //end switch

} //end while

delete myData;

return 0;

}

Input Structure:

The input txt file will have the following structure – I have annotated here for understanding and these annotations will not be in the actual input file. After the first two lines, the remaining lines in the input txt file contains commands (one command per line), where there can be up to 6 different commands in any order with any number of entries. The command is indicated by an integer [1 to 6] and can be found at the beginning of each line.

counts // Number of data entries in the csv file 

Covid-19-Data-csv  // Name of the input file that contains the actual Covid-19 data by county and state

1 Cleveland, Oklahoma //command 1 here is for findTotalCasesByCounty

1 Walla Walla, Washington 

1 San Francisco, California

1 Tulsa, Oklahoma

2 Oklahoma, Oklahoma //command 2 here is for findTotalDeathsByCounty

2 Miami, Ohio

2 Miami, Oklahoma

3 Oklahoma //command 3 here is for findTotalCasesByState

3 North Carolina

4 New York //command 4 here is for findTotalDeathsByState

4 Arkansas

5 Oklahoma 2020-03-19 2020-06-06 //5 here is for findTotalCasesBySateWithDateRange

6 New York 2020-04-01 2020-06-06 //6 here is for findTotalDeathsBySateWithDateRange

Redirected Input

Redirected input provides you a way to send a file to the standard input of a program without typing it using the keyboard. To use redirected input in Visual Studio environment, follow these steps: After you have opened or created a new project, on the menu go to project, project properties, expand configuration properties until you see Debugging, on the right you will see a set of options, and in the command arguments type “< input filename”. The < sign is for redirected input and the input filename is the name of the input file (including the path if not in the working directory). A simple program that reads character by character until it reaches end-of-file can be found below.

#include <iostream>

using namespace std;

//The character for end-of-line is ‘n’ and you can compare c below with this 

//character to check if end-of-line is reached.

int main () {

char c;

cin.get(c);

while (!cin.eof()) {

cout << c;

cin.get(c);

}

return 0;

}

C String

A string in the C Programming Language is an array of characters ends with ‘’ (NULL) character. The NULL character denotes the end of the C string. For example, you can declare a C string like this:

char aCString[9];

Then you will be able to store up to 8 characters in this string. You can use cout to print out the string and the characters stored in a C string will be displayed one by one until ‘’ is reached. Here are some examples:

0

1

2

3

4

5

6

7

8

cout result

Length

u

s

e

r

n

a

m

e

username

8

n

a

m

e

name

4

n

a

m

e

1

2

3

4

name

4

(nothing)

0

Similarly, you can use a for loop to determine the length of a string (NULL is NOT included). We show this in the following and also show how you can dynamically create a string using a pointer

char aCString[] = “This is a C String.”; // you don’t need to provide

// the size of the array

// if the content is provided

char* anotherCString; // a pointer to an array of

// characters

unsigned int length = 0;

while( aCString[length] != ‘’)

{

length++;

}

// the length of the string is now known

anotherCString = new char[length+1]; // need space for NULL character

// copy the string

for( int i=0; i< length+1; i++)

 anotherCString[i] = aCString[i];

 cout << aCString << endl; // print out the two strings

cout << anotherCSring << endl;

delete [] anotherCString; // release the memory after use

You can check http://www.cs.bu.edu/teaching/cpp/string/array-vs-ptr/, other online sources or textbooks to learn more about this.

Output Structure

Stay tuned for the exact format in which the output of your program should be formatted. For now, it is recommended to start working on reading in the input files, storing the data, and accessing the data based on the given commands.

Constraints

1. In this project, the only header you will use is #include <iostream> and using namespace std.

2. None of the projects is a group project. Consulting with other members of this class our seeking coding solutions from other sources including the web on programming projects is strictly not allowed and plagiarism charges will be imposed on students who do not follow this.

Rules for Gradescope (Project 1):

1. Students have to access GradeScope through Canvas using the GradeScope tab on the left, or by clicking on the Project 1 assignment submission button.

2. Students should upload their program as a single cpp file and cannot have any header files. If, there are header files (for classes) you need to combine them to a single cpp file and upload to GradeScope.

3. Students have to name their single cpp file as ‘project1.cpp’. All lower case. The autograder will grade this only if your program is saved as this name.

4. Sample input files and output files are given. Your output should EXACTLY match the sample output file given. Please check the spaces and new lines before your email us telling that the ‘output exactly matches but not passing the test cases’. Suggest using some type of text comparison to check your output with the expected.

5. Students need to have only one header file(iostream) while uploading to GradeScope. You cannot have ‘pch.h’ or ’stdafx.h’.

6. Students cannot have ‘system pause’ at the very end of the cpp file.

Get 20% Discount on This Paper
Pages (550 words)
Approximate price: -

Try it now!

Get 20% Discount on This Paper

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Custom Writings Help is a Quality-Oriented Company in Online Writing as a result of hiring exceptional professionals to execute clients' tasks.

Essays

Research Papers

At Custom Writings Help,We understand the struggle of research paper writing, and that is why at Custom WritingS Help, we are all out to help you. We pride ourselves on having a team of clinical writers. The stringent and rigorous vetting process ensures that only the 'BEST' Writers are chosen for the job. We have highly qualified Ph.D. and MA writers working with us; we equally offer these experienced writers specific bonuses and incentives to make them deliver highly original, unique, and informative content at reasonably low prices.

Admissions

Thesis Writing Service

Worlwide, Many Masters Students are struggling with Thesis Completion. A thesis is likely to be the longest and most challenging piece of work a student has ever completed. However, unlike essays and other assignments, a student can pick a particular interest topic and work on their initiative. Fortunately, we are there for you. At Custom Writings Help, you are assured of an authentic, imaginative, informative, linguistically great, and advantageous thesis that adheres to all your needs. So, why continue considering different writers when you have discovered the best in the field?

Editing

Custom Papers

Not a single student can avoid writing custom papers. However, a total lack of experience, skills, and time makes it very hard to produce a superb writing piece. Therefore, if you are seeking professional help, turn to us. Our specialized and experienced writers compose a variety of model papers, including custom essays, college term papers, research papers, book reports, MBA essays, executive summaries, dissertations, Ph.D. theses, admission essays, and research proposals for college and university students at any level.

Coursework

Essay Writing

Most of the students disregard the critical principles of essay writing and compose papers below sensible guidelines. Therefore, with Custom Writings Help, one should not worry about his/her essay. Our Writers compose informative and engaging content on all complexities and topics. We write meaningful and smart essays while prioritizing all aspects that bring about a good grade, such as impeccable grammar, proper structure, zero-plagiarism, and conformance to guidelines.

Coursework

Coourse Work Writing

Don't let the seemingly never-ending onslaught of writing assignments get you down. If you are looking where to get course work assistance online, the writers at Custom Writings Help are here to assist you with all of your writing needs. We undertake to unique delivery of papers that meet the professor's requirements. The content is proofread, edited, and checked plagiarism before submission to customers. No matter how big or small your work is, we will deliver on time. Try US Now! !

Coursework

Dissertation Writing Service

High-Quality Dissertation Writing Services are rare. They require Ph.D. academicians – not easily found. However, are an exception. The years, time, and resources we have invested in the dissertation world has given us a competitive advantage over others. Choose to come to Custom Writings Help; You will find perfect Ph.D. consultants who have written hundreds of dissertations theses ready to help you. Let our dissertation-writing services help you craft your dissertation, for you are assured we will give you the results.