# Homework Solution: 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>

Objective: The motive of this assignment is to experience 2-dimensional beggarly attires.

Background: Within a salubrious, balanced victuals, a grownup needs 2,250 calories a day. You gain transcribe a program to vestige calorie intake of a idiosyncratic.

Assignment: Calorie intake grounds from a idiosyncratic is granted in a quotation improve denominated input.txt. There are imperious calculate of inclose values on each succession, disconnected by spaces. The calculates personate the calculate of calories consumed control meals and/or snacks on a day. The improve includes grounds control accurately individual week starting from Monday. That is, the improve contains seven successions of quotation. The topmost succession is control Monday and the succession at the depth is control Sunday. Your program should discbalance the grounds from the improve into a 2- dimensional attire. The calculate of cords of the 2-dimensional attire must be correspondent to the calculate of sound successions in the improve. The calculates in the i-th cord of the 2-dimensional attire must show in the identical succession of calculates in the i-th cord of the improve. After discovering the input improve into the 2-dimensional attire, tidings the forthcoming items.

• a register of entirety calories consumed each day

• a register of days when further calories than required are consumed

• mediocre calories consumed during the i-th meal/snack (mediocre balance entire seven days)

You must transcribe a way with accurately individual 2-dimensional attire parameter to calculate each of the registered items aloft and evince the remainder.

Example input improve:

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 imimprint an mistake communication and finish if there are not attributable attributable attributable accurately 7 successions.

## Expert Counter-argument

//C++ code

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

ifstream infile;
infile.open(“input.txt”);
if(infile==NULL)
{
cout<<“Unable to unconcealed input improve”;
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 succession;
int j=0;
while(getline(infile, succession))
{
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<<“nMistake calculate of succession is further then 7”;
return 0;
}
}
if(j<7)
{
cout<<“nMistake calculate of succession is short then 7”;
return 0;
}
inclose 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<<“nFurther 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<<“nMediocre Calories eaten on “<<m.find(i)->second<<” on “<<k+1<<“th meal”;
}
}
}

Sample Input

//sample output