I have a problem to solve, and I came so close with algorithm, but I am having hard time organizing them so they work.

I will post the question and the codes I have.

Can someone help me organizing them?

The program is expected to read input information from a textfile called “grade.txt” and write its output to the terminal.

The format of the input file is: First line will have two integer values, as x and y.

For example, 3 and 4. First number, 3, indicates the number of the students. Second number, 4, specifies the number of homework. There will be x rows, each with y columns (3 rows and 4 columns) where each column will hold a grade between 0-100. Below, you can see the contents of a possible input file:

3 3
92 90 70
80 90 20
90 70 88

Your program is to calculate the average of any number of grades (expect up to 10 grades in each row). Include at least 3 functions:
• main, which declares the a two-dimensional grades array (10 by 10), calls the other methods, and writes output of the grades, their average and a letter grade ( >= 90 is A, >= 80 is B, >=70 is C, >= 60 is D, and E otherwise).
• get_grades, which gets input of integer grades from a file to the 2-dimensional array.
• calculate_average, which uses the grades array and passes the average back to main.

``````#include <iostream>
#include <fstream>
using namespace std;

{
int student;
int hw;
in_stream >> student;
in_stream >> hw;
ifstream OpenFile;				// ifstream --> input
char ch;
while (OpenFile)
{
OpenFile.get(ch);
cout << ch;
}

for (int i=0; i< student; i++)
for (int j=0; j<hw ; j++)
}

int calculate_average (main)				// calculate average //
{
int Avg (int[],int)
int total = 0;
for (int k=0; k<Avg; k++)
total += student_1[k];
return (total/hw)
}

int main ()									// MAIN //
{
int student_1[10];
for (int i=0; i<student_1; i++)
cout << "student # " << i << "\t";

{
for (int j=0; j<hw ; j++)
cout << gradebook [i][j] << "\t";
}

int avg (student_1[], hw);

int  Avg = total / 100;
switch (temp)
{
case 100 : grade = 'A Plus!';
break;
case  90 : grade = 'A';
break;
case  80 : grade = 'B';
break;
case  70 : grade = 'C';
break;
case  60 : grade = 'D';
break;
} // switch

cout << endl;
}``````

## All 8 Replies

always have a return statement at int main to properly stop the execution and also at the non void functions

hm. ok. is there anywhere that you think I should get rid of or fix?

I'm not yet adept at C++,I just know the fundamentals, so I think you need to wait for veteran members to have a look at it :)

OK, you posted your assignment. You posted your code. But you didn't explain exactly what you want help with. "Organize" is not a specific enough question. Although proper formatting would be a really good start. It helps you. It helps us. And your instructor won't have to work so hard checking the code so it helps him, too.

Hi There

I agree with Walt 100% and I would just like to add the following:

1 thing I see is that your assignment requires you to create the 2-dimensional array in your main()... I'll leave the rest

1 other thing, and this is not a requirement at all, but I found it helps me a lot to add as many as possible comments to my code to not only explain it to others when I need help, but to enable me to read the flow of my program easier,

That way proper formatting becomes evident,

The first opinion you should get is that of your compiler.
This code will not compile.

Organizing it is important, but not quite as important as making it functional (and following the actual instructions).

Step through it mentally and think about WHEN things are to happen.

Organizing it is important, but not quite as important as making it functional (and following the actual instructions).

I completely disagree.
A good organization is best done when designing and writing the code -- long before it's functional. This makes making it functional easier.

Organizing after it's functional simply means
1) it takes longer to get it functional
2) a lot of work getting the mess organized after it's functional
3) fixing the code after organization has broken it.
IOW - it takes 3-4 times longer to create a single program.

After a while, a developer can imagine "chunks-of-functionality" and immediately put the code into that arrangement -- and for the long term serves a greater purpose.

...but that comes with experience.

commented: That liast bit is the key. NOW I agree with you! +17
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.