# Answered Essay: Objective: The goal of this assignment is to practice 2-dimensional ragged array

Objective: The goal of this assignment is to practice 2-dimensional ragged arrays.

Background: Within a healthy, balanced diet, a grownup needs 2,250 calories a day. You will write a program to track calorie intake of a person.

Assignment: Calorie intake data from a person is provided in a text file named input.txt. There are arbitrary number of double values on each line, separated by spaces. The numbers represent the number of calories consumed for meals and/or snacks on a day. The file includes data for exactly one week starting from Monday. That is, the file contains seven lines of text. The topmost line is for Monday and the line at the bottom is for Sunday. Your program should read the data from the file into a 2- dimensional array. The number of rows of the 2-dimensional array must be equal to the number of valid lines in the file. The numbers in the i-th row of the 2-dimensional array must appear in the same sequence of numbers in the i-th row of the file. After reading the input file into the 2-dimensional array, report the following items.

• a list of total calories consumed each day

• a list of days when more calories than required are consumed

• average calories consumed during the i-th meal/snack (average over all seven days)

You must write a method with exactly one 2-dimensional array parameter to compute each of the listed items above and display the result.

Example input file:

800 1000 100

450 100 845 20 1200 200

1800 250 400

0 1500 800 120

600 500 700 1400 1700 100

675

You should print an error message and terminate if there are not exactly 7 lines.

//C++ code

#include<iostream>
#include<fstream>
#include<map>
using namespace std;
int main()
{
map<int,string> m;
m.insert(pair <int,string>(0,”Monday”));
m.insert(pair <int,string>(1,”Tuesday”));
m.insert(pair <int,string>(2,”Wednesday”));
m.insert(pair <int,string>(3,”Thursday”));
m.insert(pair <int,string>(4,”Friday”));
m.insert(pair <int,string>(5,”Saturday”));
m.insert(pair <int,string>(6,”Sunday”));

ifstream infile;
infile.open(“input.txt”);
if(infile==NULL)
{
cout<<“Unable to open input file”;
return 0;
}
int arr[7][100];
for(int i=0;i<7;i++)
{
for(int j=0;j<100;j++)
arr[i][j]=0;
}
string line;
int j=0;
while(getline(infile, line))
{
int i=0;
int k=0;
while(line[i]!=’’)
{
if(line[i]==’ ‘)
{
k++;
}
else
{
arr[j][k]=arr[j][k]*10+line[i]-48;
}
i++;
}
j++;
if(j>7)
{
cout<<“nError number of line is more then 7”;
return 0;
}
}
if(j<7)
{
cout<<“nError number of line is less then 7”;
return 0;
}
double avg=0;
int count=0;
int Ceach[7];
for(int i=0;i<7;i++)
{
Ceach[i]=0;
for(int k=0;arr[i][k]!=0;k++)
{
count++;
avg+=arr[i][k];
Ceach[i]+=arr[i][k];
}
cout<<“nCalories eaten on “<<m.find(i)->second<<” is “<<Ceach[i];
}
avg=avg/count;
for(int i=0;i<7;i++)
{
if(Ceach[i]>2250)
cout<<“nMore Calories eaten on “<<m.find(i)->second;;
}
for(int i=0;i<7;i++)
{
for(int k=0;arr[i][k]!=0;k++)
{
if(avg==arr[i][k])
cout<<“nAverage Calories eaten on “<<m.find(i)->second<<” on “<<k+1<<“th meal”;
}
}
}

Sample Input

//sample output

Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

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

Proceed with the payment

Choose the payment system that suits you most.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.