Array problem. HELP PLEASE

So I have this activity for programming class and so far these are the codes I came up with. I'm only allowed to place codes where it says "add code here". Anybody lend me a hand here. Thanks :D

/*
* Programmer: Bretaña, Fidel Jhon A.
* Date Created: 7/31/2012
* Terminal No: 13
* Program: MSIT
* Course / Section: CS127L/BC1
* Purpose: This program will calculate frequency and grade.
*/
#include<iostream>
#include<iomanip>
#include<cstdlib>
using namespace std;

const int size =10;
int choiceMenu();

void FREQUENCY(int list[],int lsize);
void fGrade();
void viewGrade(double ggrade[][5]);
int tryAgain(char y);

void main()

{
system("cls");
choiceMenu();
int menu;
cout<<"Enter your choice: ";
cin>>menu;

//add code here declaration/called function

switch (menu)
{

case 1:
FREQUENCY();//add code here for frequency

break;
case 2:
fGrade();//add code here final grade

break;
case 3: cout<<"TERMINATING....";
exit(1);

}

//add code here statement/called function

}
/////////////////////////////////////////CHOICE MENU//////////////////////////////////////////////////////////////

int choiceMenu()
{
int option;
cout<<"-----MENU-----"
<<"1D - FREQUENCY \n"
<<"2D - GRADE\n"
<<"[3] EXIT \n"
<<"\n";

do{
cin>>option;

if(option>3||option<1)
{
cout<<"Invalid Input. Please Enter Again.\n[ ] ";
}

}while(option>3||option<1);

return option;
//add code here in processing choice menu

}


void FREQUENCY(int list[10],int lsize)
{
system("cls");
cout<<endl;
cout<<"Enter numbers from 11 - 20";
const int size=10;
double meh[size];
int index;

for(lsize=0;lsize<10;lsize++)
cin>>list[lsize];



//add code here display of frequency


}
//////////////////////////////////////////INPUT GRADE///////////////////////////////////////////////////////////////
void fGrade()
{
system("cls");
cout<<endl;
cout<<"ENTER GRADES FOR A 3X5 ARRAY"<<endl;
const int srows = 5;
const int scol = 3;
int matrix[srows][scol];
int ir,ic;

//add code here : for the input of 15 grades in 3x5 array
//calling function viewgrade
}
///////////////////////////////////////////////////////VIEW GRADES/////////////////////////////////////////////////////
void viewGrade(double ggrade[][5])
{
//add code here : display the 3x5 array of grades and process of choices for viewing the grade
}//end viewGrade
//////////////////////////////////////////////TRY AGAIN//////////////////////////////////////////////////////////////////
int tryAgain(char y)
{

//add code here : if parameter y value is 'Y' or 'y' return value 1
//else return value -1
}
Last edited on
Use code tags.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Programmer: Bretaña, Fidel Jhon A.
* Date Created: 7/31/2012
* Terminal No: 13
* Program: MSIT
* Course / Section: CS127L/BC1
* Purpose: This program will calculate frequency and grade.
*/
#include<iostream>
#include<iomanip>
#include<cstdlib>
using namespace std;

const int size =10;
int choiceMenu();

void FREQUENCY(int list[],int lsize);
void fGrade();
void viewGrade(double ggrade[][5]);
int tryAgain(char y);

void main()

{
system("cls");
choiceMenu();
int menu;
cout<<"Enter your choice: ";
cin>>menu;

//add code here declaration/called function

switch (menu)
{

case 1:
FREQUENCY();//add code here for frequency

break;
case 2:
fGrade();//add code here final grade

break;
case 3: cout<<"TERMINATING....";
exit(1);

}

//add code here statement/called function

}
/////////////////////////////////////////CHOICE MENU//////////////////////////////////////////////////////////////

int choiceMenu()
{
int option;
cout<<"-----MENU-----"
<<"1D - FREQUENCY \n"
<<"2D - GRADE\n"
<<"[3] EXIT \n"
<<"\n";

do{
cin>>option;

if(option>3||option<1)
{
cout<<"Invalid Input. Please Enter Again.\n[ ] ";
}

}while(option>3||option<1);

return option;
//add code here in processing choice menu

}


void FREQUENCY(int list[10],int lsize)
{
system("cls");
cout<<endl;
cout<<"Enter numbers from 11 - 20";
const int size=10;
double meh[size];
int index;

for(lsize=0;lsize<10;lsize++)
cin>>list[lsize];



//add code here display of frequency


}
//////////////////////////////////////////INPUT GRADE///////////////////////////////////////////////////////////////
void fGrade()
{
system("cls");
cout<<endl;
cout<<"ENTER GRADES FOR A 3X5 ARRAY"<<endl;
const int srows = 5;
const int scol = 3;
int matrix[srows][scol];
int ir,ic;

//add code here : for the input of 15 grades in 3x5 array
//calling function viewgrade
}
///////////////////////////////////////////////////////VIEW GRADES/////////////////////////////////////////////////////
void viewGrade(double ggrade[][5])
{
//add code here : display the 3x5 array of grades and process of choices for viewing the grade
}//end viewGrade
//////////////////////////////////////////////TRY AGAIN//////////////////////////////////////////////////////////////////
int tryAgain(char y)
{

//add code here : if parameter y value is 'Y' or 'y' return value 1
//else return value -1
}
dude, you didn't answer my problem
Anyway, so far this is the only code that I came up with. I'm having problems with supplying codes with the others.

/*
* Programmer: Bretaña, Fidel Jhon A.
* Date Created: 7/31/2012
* Terminal No: 13
* Program: MSIT
* Course / Section: CS127L/BC1
* Purpose: This program will calculate frequency and grade.
*/
#include<iostream>
#include<iomanip>
#include<cstdlib>
using namespace std;

const int size =10;
int choiceMenu();

void FREQUENCY(int list[],int lsize);
void fGrade();
void viewGrade(double ggrade[][5]);
int tryAgain(char y);

void main()

{
system("cls");
choiceMenu();
int menu;
cout<<"Enter your choice: ";
cin>>menu;

//add code here declaration/called function

switch (menu)
{


case 1:
FREQUENCY();//add code here for frequency
int val,num;
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout.precision(1);
cout<<"Enter numbers from 11 to 20:\n";


break;
case 2:
fGrade();//add code here final grade

break;
case 3: cout<<"TERMINATING....";
exit(1);

}

//add code here statement/called function

}
/////////////////////////////////////////CHOICE MENU//////////////////////////////////////////////////////////////

int choiceMenu()
{
int option;
cout<<"-----MENU-----"
<<"1D - FREQUENCY \n"
<<"2D - GRADE\n"
<<"[3] EXIT \n"
<<"\n";

do{
cin>>option;

if(option>3||option<1)
{
cout<<"Invalid Input. Please Enter Again.\n[ ] ";
}

}while(option>3||option<1);

return option;
//add code here in processing choice menu

}


void FREQUENCY(int list[10],int lsize)
{
system("cls");
cout<<endl;
cout<<"FREQUENCY DISPLAY";
cout<<"NUMBER 11 = "<<list[0]<<" TIME(S)"<<endl;
cout<<"NUMBER 12 = "<<list[1]<<" TIME(S)"<<endl;
cout<<"NUMBER 13 = "<<list[2]<<" TIME(S)"<<endl;
cout<<"NUMBER 14 = "<<list[3]<<" TIME(S)"<<endl;
cout<<"NUMBER 15 = "<<list[4]<<" TIME(S)"<<endl;
cout<<"NUMBER 16 = "<<list[5]<<" TIME(S)"<<endl;
cout<<"NUMBER 17 = "<<list[6]<<" TIME(S)"<<endl;
cout<<"NUMBER 18 = "<<list[7]<<" TIME(S)"<<endl;
cout<<"NUMBER 19 = "<<list[8]<<" TIME(S)"<<endl;
cout<<"NUMBER 20 = "<<list[9]<<" TIME(S)"<<endl;



//add code here display of frequency


}
//////////////////////////////////////////INPUT GRADE///////////////////////////////////////////////////////////////
void fGrade()
{
//add code here : for the input of 15 grades in 3x5 array
system("cls");
cout<<endl;
cout<<"ENTER GRADES FOR A 3X5 ARRAY"<<endl;
const int srows = 5;
const int scol = 3;
int grades[srows][scol];
int ir,ic;
cout<<endl;
//calling function viewgrade
cout<<srows*scol<<"\n";
for(ir=0;ir<srows;ir++)
{
for(ic=0;ic<scol;ic++)
{
cout<<"NUMBER ["<<ir<<"]["<<ic<<"]:";
cin>>grades[ir][ic];
}
cout<<endl;
}
cout<<endl;

}
///////////////////////////////////////////////////////VIEW GRADES/////////////////////////////////////////////////////
void viewGrade(double ggrade[][5])
{
system("cls");
const int srows = 5;
const int scol = 3;
int grades[srows][scol];
int ir,ic;
cout<<endl;
cout<<srows*scol<<"\n";
cout<<"DISPLAY GRADE IN A 3X5 ARRAY"<<endl;
for(ir=0;ir<srows;ir++)
{
for(ic=0;ic<scol;ic++)
{
cout<<setw(5)<<grades[ir][ic];
}
cout<<endl;
}
cout<<endl;

//add code here : display the 3x5 array of grades and process of choices for viewing the grade
}//end viewGrade
//////////////////////////////////////////////TRY AGAIN//////////////////////////////////////////////////////////////////
int tryAgain(char y)
{
system("cls");
cout<<"do you want to try again? "<<endl;
cin>>y;
if(y=='y')
main();
else if(y=='n')
exit(1);

//add code here : if parameter y value is 'Y' or 'y' return value 1
//else return value -1
}
Use codetags! And make sure you're code is properly indented! And specify you're problem.
closed account (o3hC5Di1)
Hi there,

As previously mentioned, it's best to use codetags when posting code (click the <> button on the right of the textarea when posting or editing).

As to your problems:

1
2
3
4
5
6
//fgrade()
//add code here : for the input of 15 grades in 3x5 array
cout<<"ENTER GRADES FOR A 3X5 ARRAY"<<endl;
const int srows = 5;
const int scol = 3;
int grades[srows][scol];


First, it would be wise to turn those statements around as such:

1
2
3
4
const int srows = 5;
const int scol = 3;
int grades[srows][scol];
cout<<"ENTER GRADES FOR A 3X5 ARRAY"<<endl;


Your goal is to insert into the array, so it's best to declare the array before inputting values.
After asking the question, you will want to read the input from the user, this is done using cin >> .
Cout is standard output (ie screen), cin is standard input (ie keyboard).
Now, you need to fill the array - so the best thing is to ask the user for input repeatedly, which is done by loops in code. Inthis case, you'll probably want a nested loop, as described in pseudocode:

For every student (srows), use counter s
    For every grade (scols), use counter g
        Ask input
        Store input[s][g]


You will want to use the same algorithm for displaying the array, only rather than asking for input, you output the data.

It's a bit hard to tell from your code what else you are struggling with, please do get back to us with more specific questions about certain parts of the program you are struggling with if needed.

Hope that helps.

All the best,
NwN
Topic archived. No new replies allowed.