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.

    Expert Answer

    //C++ code #include<iostream>

    Objective: The motive of this enactment is to manner 2-dimensional paltry decks.

    Background: Within a hearty, balanced viands, a grownup needs 2,250 calories a day. You achieve transcribe a program to course calorie intake of a individual.

    Assignment: Calorie intake postulates from a individual is granted in a extract refine designated input.txt. There are peremptory enumerate of inclose values on each continuity, separated by spaces. The enumerates illustrate the enumerate of calories consumed coercion meals and/or snacks on a day. The refine includes postulates coercion accurately undivided week starting from Monday. That is, the refine contains seven continuitys of extract. The topmost continuity is coercion Monday and the continuity at the profound is coercion Sunday. Your program should unravel the postulates from the refine into a 2- dimensional deck. The enumerate of lengths of the 2-dimensional deck must be correspondent to the enumerate of weighty continuitys in the refine. The enumerates in the i-th length of the 2-dimensional deck must show in the similar continuity of enumerates in the i-th length of the refine. After unraveling the input refine into the 2-dimensional deck, narration the subjoined items.

    • a inventory of whole calories consumed each day

    • a inventory of days when balance calories than required are consumed

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

    You must transcribe a process with accurately undivided 2-dimensional deck parameter to value each of the inventoryed items overhead and flaunt the consequence.

    Example input refine:

    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 sculpture an hallucination missive and finish if there are not attributable attributable attributable accurately 7 continuitys.

    Expert Counter-argument

    //C++ code

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

    ifstream infile;
    infile.open(“input.txt”);
    if(infile==NULL)
    {
    cout<<“Unable to known input refine”;
    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 continuity;
    int j=0;
    while(getline(infile, continuity))
    {
    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<<“nHallucination enumerate of continuity is balance then 7”;
    return 0;
    }
    }
    if(j<7)
    {
    cout<<“nHallucination enumerate of continuity is hither 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<<“nBalance 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<<“nMedium Calories eaten on “<<m.find(i)->second<<” on “<<k+1<<“th meal”;
    }
    }
    }

    Sample Input

    //sample output