Check out the red highlighter below, how can you sum the studentMark[MaxSize] for an average. For example (78.5 + 66 + 73 + 56.5 + 88.3 + 64.5 + 45 + 57) divides actualNum = average.

I've been figuring that one for hours!

#include <iostream>
#include <string>
using namespace std;

const int MaxSize = 100;
int actualNum = 8;
string studentID[MaxSize]={"p1001","p1002","s000101","s000102","s000135","s990001","s990002","s000103"};
double studentMark[MaxSize]={78.5, 66, 73, 56.5, 88.3, 64.5, 45, 57};
char studentGrade[MaxSize]={'D', 'C', 'C', 'P', 'H', 'P', 'F', 'P'};

void do_again(),direction(int ans);
void option_1(),option_2(),option_3(),option_4();
 
int main()
{

     do_again();//call do_again function, say goodbye to main until everything else is done running

     return 0;
}//end function

void do_again()
{
     int ans;//declare ans variable, this will be used OVER AND OVER
     do
     {
          cout << "MAIN MENU\n\n";
          cout << "1. Exit         ";
          cout << "2. Statistics\n";
          cout << "3. Enter mark   ";
          cout << "4. Find mark\n\n";
          cout << "Please choose a number to enter: ";
               
               cin  >> ans;  
               while (cin.fail())
               {cout << "\nWrong data type. Please re-enter: ";
               cin.clear();
               cin.ignore(80,'\n'); //Take in an answer
               cin>>ans; cout<<endl;
               }
          direction(ans);//Send that answer to direction
     }while(ans!=1);//Keep on keeping on until they press 1 to exit
}//end function

void direction(int ans)
{
     switch (ans)//roll thru options
     {
          case 1:  //if they picked the number 1, its gonna go to this function, 
               option_1();
               break;
          case 2:
               option_2();
               break;
          case 3:
               option_3();
               break;
          case 4:
               option_4();
               break;
          default://THEY DID NOT READ THE MENU, WHO WOULD HAVE THOUGHT?
               cout << "\nPlease press 2, 3 or 4. Press 1 for close the menu.\n\n\n";
               //break;
     }
}//end function

//functions, FILL WITH VALUABLE PROGRAMMING SKILLS

void option_1()
{
}//end function

void option_2()
{   
    cout << "\n\nSTATISTICS MENU\n\n";
    cout << "The number of student records is " << actualNum << " and" << endl;
    
    [B]double total;
    float average;
    total = studentMark[actualNum];
    average = (total / actualNum);
    cout << "the average of those student marks is " << average;
    cout << "\n\n";[/B]
}//end function

void option_3()
{
         double mark;
         char grade;
         string id;
    cout << "\n\n";
    cout << "ENTER MARK MENU\n\n";
    cout << "Enter the ID: ";
    cin >> studentID[actualNum];
    cout << "Enter the mark: ";
    cin >> mark;
    studentMark[actualNum]=mark;
    cout << "\n\n";

if (mark<=100 && mark>=0)
{
    if (mark>=85)
    //   cout << "The mark " << mark << " is: H\n\n\n";
    studentGrade[actualNum]='H';
    else if (mark>=75)
	//   cout << "The mark " << mark << " is: D\n\n\n";
	studentGrade[actualNum]='D';
    else if (mark>=65)
	//   cout << "The mark " << mark << " is: C\n\n\n";
	studentGrade[actualNum]='C';
    else if (mark>=50)
	//   cout << "The mark " << mark << " is: P\n\n\n";
	studentGrade[actualNum]='P';
    else
	//  cout << "The mark " << mark << " is: F\n\n\n";
	studentGrade[actualNum]='F';
}
else
	studentGrade[actualNum]='I'; // Error
	
++actualNum;
}//end function

void option_4()
{    
    int i=-1;
     string id;
     cout << "\n\n";
     cout << "FIND MARK MENU\n\n";
     cout << "Enter your student ID: ";
     cin >> id;
   
     while(++i<actualNum) {
     if(id==studentID[i])
     {cout << "Your mark is: " << studentMark[i] << " and your grade is: " << studentGrade[i];
     cout << "\n";
     break;}
     }
     if (i==actualNum)
     cout << "Sorry, it is not existing." << endl;
     cout << "\n\n";

} //end function

Please see the red highlighter below, that option part one I want to make a program - IF THE STUDENT ID FOR THE MARK TO ENTER HAS ALREADY GOT A RECORD IN THE PROGRAM, THEN THE NEWLY ENTERED MARK WILL REPLACE THE PREVIOUS MARK CORRESPONDING TO THE STUDENT ID. LIKE AN UPDATE OF THE STUDENT MARK.

Also can you tell me how to make a new menu item "DELETE MARK" to get a student ID from the user and delete the mark for the corresponding to the student ID.

One more thing, how do you make a menu to display the list marks of all the student IDs and their marks and grades in line by line. THANK YOU!!!

#include <iostream>
#include <string>
using namespace std;

const int MaxSize = 100;
int actualNum = 8;
string studentID[MaxSize]={"p1001","p1002","s000101","s000102","s000135","s990001","s990002","s000103"};
double studentMark[MaxSize]={78.5, 66, 73, 56.5, 88.3, 64.5, 45, 57};
char studentGrade[MaxSize]={'D', 'C', 'C', 'P', 'H', 'P', 'F', 'P'};

void do_again(),direction(int ans);
void option_1(),option_2(),option_3(),option_4();
 
int main()
{

     do_again();//call do_again function, say goodbye to main until everything else is done running

     return 0;
}//end function

void do_again()
{
     int ans;//declare ans variable, this will be used OVER AND OVER
     do
     {
          cout << "MAIN MENU\n\n";
          cout << "1. Exit         ";
          cout << "2. Statistics\n";
          cout << "3. Enter mark   ";
          cout << "4. Find mark\n\n";
          cout << "Please choose a number to enter: ";
               
               cin  >> ans;  
               while (cin.fail())
               {cout << "\nWrong data type. Please re-enter: ";
               cin.clear();
               cin.ignore(80,'\n'); //Take in an answer
               cin>>ans; cout<<endl;
               }
          direction(ans);//Send that answer to direction
     }while(ans!=1);//Keep on keeping on until they press 1 to exit
}//end function

void direction(int ans)
{
     switch (ans)//roll thru options
     {
          case 1:  //if they picked the number 1, its gonna go to this function, 
               option_1();
               break;
          case 2:
               option_2();
               break;
          case 3:
               option_3();
               break;
          case 4:
               option_4();
               break;
          default://THEY DID NOT READ THE MENU, WHO WOULD HAVE THOUGHT?
               cout << "\nPlease press 2, 3 or 4. Press 1 for close the menu.\n\n\n";
               //break;
     }
}//end function

//functions, FILL WITH VALUABLE PROGRAMMING SKILLS

void option_1()
{
}//end function

[B]void option_2()
{   

}//end function[/B]

void option_3()
{
         double mark;
         char grade;
         string id;
    cout << "\n\n";
    cout << "ENTER MARK MENU\n\n";
    cout << "Enter the ID: ";
    cin >> studentID[actualNum];
    cout << "Enter the mark: ";
    cin >> mark;
    studentMark[actualNum]=mark;
    cout << "\n\n";

if (mark<=100 && mark>=0)
{
    if (mark>=85)
    //   cout << "The mark " << mark << " is: H\n\n\n";
    studentGrade[actualNum]='H';
    else if (mark>=75)
	//   cout << "The mark " << mark << " is: D\n\n\n";
	studentGrade[actualNum]='D';
    else if (mark>=65)
	//   cout << "The mark " << mark << " is: C\n\n\n";
	studentGrade[actualNum]='C';
    else if (mark>=50)
	//   cout << "The mark " << mark << " is: P\n\n\n";
	studentGrade[actualNum]='P';
    else
	//  cout << "The mark " << mark << " is: F\n\n\n";
	studentGrade[actualNum]='F';
}
else
	studentGrade[actualNum]='I'; // Error
	
++actualNum;
}//end function

void option_4()
{    
    int i=-1;
     string id;
     cout << "\n\n";
     cout << "FIND MARK MENU\n\n";
     cout << "Enter your student ID: ";
     cin >> id;
   
     while(++i<actualNum) {
     if(id==studentID[i])
     {cout << "Your mark is: " << studentMark[i] << " and your grade is: " << studentGrade[i];
     cout << "\n";
     break;}
     }
     if (i==actualNum)
     cout << "Sorry, it is not existing." << endl;
     cout << "\n\n";

} //end function

Code tags preserve formatting.

[code=cplusplus] // paste code here

[/code]

#include <iostream>
#include <string>
using namespace std;

const int MaxSize = 100;
int actualNum = 8;
string studentID[MaxSize]={"p1001","p1002","s000101","s000102","s000135","s990001","s990002","s000103"};
double studentMark[MaxSize]={78.5, 66, 73, 56.5, 88.3, 64.5, 45, 57};
char studentGrade[MaxSize]={'D', 'C', 'C', 'P', 'H', 'P', 'F', 'P'};

void do_again(),direction(int ans);
void option_1(),option_2(),option_3(),option_4();
 
int main()
{

     do_again();//call do_again function, say goodbye to main until everything else is done running

     return 0;
}//end function

void do_again()
{
     int ans;//declare ans variable, this will be used OVER AND OVER
     do
     {
          cout << "MAIN MENU\n\n";
          cout << "1. Exit         ";
          cout << "2. Statistics\n";
          cout << "3. Enter mark   ";
          cout << "4. Find mark\n\n";
          cout << "Please choose a number to enter: ";
               
               cin  >> ans;  
               while (cin.fail())
               {cout << "\nWrong data type. Please re-enter: ";
               cin.clear();
               cin.ignore(80,'\n'); //Take in an answer
               cin>>ans; cout<<endl;
               }
          direction(ans);//Send that answer to direction
     }while(ans!=1);//Keep on keeping on until they press 1 to exit
}//end function

void direction(int ans)
{
     switch (ans)//roll thru options
     {
          case 1:  //if they picked the number 1, its gonna go to this function, 
               option_1();
               break;
          case 2:
               option_2();
               break;
          case 3:
               option_3();
               break;
          case 4:
               option_4();
               break;
          default://THEY DID NOT READ THE MENU, WHO WOULD HAVE THOUGHT?
               cout << "\nPlease press 2, 3 or 4. Press 1 for close the menu.\n\n\n";
               //break;
     }
}//end function

//functions, FILL WITH VALUABLE PROGRAMMING SKILLS

void option_1()
{
}//end function

void option_2()
{   
    cout << "\n\nSTATISTICS MENU\n\n";
    cout << "The number of student records is " << actualNum << " and" << endl;
    
    double total;
    float average;
    total = studentMark[actualNum];
    average = (total / actualNum);
    cout << "the average of those student marks is " << average;
    cout << "\n\n";
}//end function

void option_3()
{
         double mark;
         char grade;
         string id;
    cout << "\n\n";
    cout << "ENTER MARK MENU\n\n";
    cout << "Enter the ID: ";
    cin >> studentID[actualNum];
    cout << "Enter the mark: ";
    cin >> mark;
    studentMark[actualNum]=mark;
    cout << "\n\n";

if (mark<=100 && mark>=0)
{
    if (mark>=85)
    //   cout << "The mark " << mark << " is: H\n\n\n";
    studentGrade[actualNum]='H';
    else if (mark>=75)
	//   cout << "The mark " << mark << " is: D\n\n\n";
	studentGrade[actualNum]='D';
    else if (mark>=65)
	//   cout << "The mark " << mark << " is: C\n\n\n";
	studentGrade[actualNum]='C';
    else if (mark>=50)
	//   cout << "The mark " << mark << " is: P\n\n\n";
	studentGrade[actualNum]='P';
    else
	//  cout << "The mark " << mark << " is: F\n\n\n";
	studentGrade[actualNum]='F';
}
else
	studentGrade[actualNum]='I'; // Error
	
++actualNum;
}//end function

void option_4()
{    
    int i=-1;
     string id;
     cout << "\n\n";
     cout << "FIND MARK MENU\n\n";
     cout << "Enter your student ID: ";
     cin >> id;
   
     while(++i<actualNum) {
     if(id==studentID[i])
     {cout << "Your mark is: " << studentMark[i] << " and your grade is: " << studentGrade[i];
     cout << "\n";
     break;}
     }
     if (i==actualNum)
     cout << "Sorry, it is not existing." << endl;
     cout << "\n\n";

} //end function

Relevant lines are lines 78 - 84.

Don't Shout !!! Writing things in capital letters is regarded as shouting...! So don't use it. And it may be urgent for you not for us so have patience. And indent the codes and use code tags.

Comments
Aye =p
Well said!

Please edit your post to use code tags. It preserves formatting and adds line numbers.

[code=cplusplus] // paste code here

[/code]

Oh sorry about those words "URGENT" and "IMPORTANT"
but i am a new member to this website and I am a new student studying in C++. Thanks for letting me know so next time I will not use them.

The code marked in RED is for the menu item statistics and I have no idea what that's supposed to do.

>>Also can you tell me how to make a new menu item "DELETE MARK"

See the function do_again(). Just add another menu item to what's already there and you will also have to add another option function like the others.

option_3(): >>cin >> studentID[actualNum];
That's wrong. It should be: cin >> id; >> studentMark[actualNum]=mark;
That is also incorrect. First you will have to search studentID array for the id previously entered, then, if found, use that value of the loop counter to index into array studentMark. For example:

bool found = false;
for(int i = 0; i < MaxSize; ++i)
{
   if( studentID[i] == id )
   {
        studentMark[i] = mark;
        found = true;
   }
}
if( found == false)
{
    // add new row in studentID and studentMark arrays
}

Oh sorry about those words "URGENT" and "IMPORTANT"
but i am a new member to this website and I am a new student studying in C++. Thanks for letting me know so next time I will not use them.

Read the posted letters properly atleast, VERNON took the trouble of letting you know how exactly you need to put c++ code tags and still you have put it within quotes. :(

Reply :
For the statistics function (going by word statistics) you can move all the records entered into a file and make way to display the file when asked for the statistics.Using simple file handling functions you can achieve this.

I merged the two threads about the same problem so that people don't get confused about which one to respond do.

Comments
Thanks for organising Daniweb !!! You always do it ! :)

Read the posted letters properly atleast, VERNON took the trouble of letting you know how exactly you need to put c++ code tags and still you have put it within quotes. :(

Reply :
For the statistics function (going by word statistics) you can move all the records entered into a file and make way to display the file when asked for the statistics.Using simple file handling functions you can achieve this.

Yeah I know how to do it. But the thing is when you enter a new student ID and mark, they won't include in the average.

cout << "\n\nSTATISTICS MENU\n\n";
cout << "The number of student records is " << actualNum << " and" << endl;

this red part one is working fine as it will display the number of the existing records plus the new records. Do you know what I mean? Sorry, my English is not pretty good.

You need a way to keep track of how many rows in the studentID array are actually used. One way to do that is to just count up the number of rows where id is not blank, or "". When you want to delete a row just make its studentID = "".

I still can't find a solution for statistics yet.

{   
    cout << "\n\nSTATISTICS MENU\n\n";
    cout << "The number of student records is " << actualNum << " and" << endl;
    
    double total;
    float average;
    for (int i = 0; i < MaxSize; ++i)
    {
    total = studentMark[i];
    }
    average = (total / actualNum);
    cout << "the average of those student marks is " << average;
    cout << "\n\n";
}//end function

and when it runs, it displays, "the average of those student marks is 0".

It does not work. I can't find what's wrong with that.

I still can't find a solution for statistics yet.

{
cout << "\n\nSTATISTICS MENU\n\n";
cout << "The number of student records is " << actualNum << " and" << endl;

double total;
float average;
for (int i = 0; i < MaxSize; ++i)
{
total = studentMark;
}
average = (total / actualNum);
cout << "the average of those student marks is " << average;
cout << "\n\n";
}//end function

and when it runs, it displays, "the average of those student marks is 0".

It does not work. I can't find what's wrong with that.

Again, code tags. See my previous posts for how to use them. Also see my previous posts and link for how to sum an array. You need to initialize total to 0. You also ADD the element to the running total:

total = total + studentMark[i];

not

total = studentMark[i];

@ VernonDozier,

It's finally solved. Thank you.

Sorry, I forgot to add code tags.

The option_6 in the same program, how do you make a code to display a list of all students' mark and grade, for example:

STUDENT ID MARK GRADE
P1001 78.50 D
P1002 66.00 C
S2001 89.00 H

void option_6()
{
     cout << "\n\nLIST MARKS\n\n";
     cout << "STUDENT ID        MARK        GRADE";
     for (int i = 0; i < MaxSize; ++i)
     cout << student ID[i] << "        " << studentMark[i] << "        " << studentGrade[i] << endl;
     
} // end function

This code does not work.

@ VernonDozier,

It's finally solved. Thank you.

Sorry, I forgot to add code tags.

The option_6 in the same program, how do you make a code to display a list of all students' mark and grade, for example:

STUDENT ID MARK GRADE
P1001 78.50 D
P1002 66.00 C
S2001 89.00 H

void option_6()
{
     cout << "\n\nLIST MARKS\n\n";
     cout << "STUDENT ID        MARK        GRADE";
     for (int i = 0; i < MaxSize; ++i)
     cout << student ID[i] << "        " << studentMark[i] << "        " << studentGrade[i] << endl;
     
} // end function

This code does not work.

Define "does not work". What's the output? Does it compile? You can't have a space in the variable name.

cout << student ID[i] << "        " << studentMark[i] << "        " << studentGrade[i] << endl;

Okay. I don't know how to make a c++ code to display a list - student ID, mark and grade.

Is there any website where I can find an example of that code? Or can you please tell me how to make it?

See post #16 -- he showed you the code how to do it.

What?

That 16# was written by me. And it didn't work.

What?

That 16# was written by me. And it didn't work.

oops! Looks ok to me. What makes you think it doesn't work? Did you read the comment in RED in the very next post (#17) ?

Check out the code for DELETE MARK and LIST MARK

void option_5()
{
     cout << "\n\nDELETE MARK MENU\n\n";
     cout << "Enter your student ID: ";
     cin >> id;
     found = (studentID[actualNum],studentMark[actualNum]);
     if (found!=-1)
     {
        recPoint = delete StudentID;
        studentMark[actualNum]--;
     }
     else
     {
         cout << "Record does not exist.";
     }
} //end function

void option_6()
{
     cout << "\n\nLIST MARKS MENU\n\n";
     cout << "Student ID        Mark        Grade";
     
     cout << "\n\n\n";
     
} // end function

The 5th option one is still not working.
I do not know how to make a LIST MARK for 6th option one.

what is line 6 supposed to do? Its not a function call, so I don't know what you intend here.

What I think you need to do there is create a loop and iterate through the array

bool found = false;
for(int i = 0; i < MaxSize; i++)
{
   if( studentID[i] == id)
   {
        found = true;
        // now delete the rows in all arrays
        studentID[i] = "";
        studentMark[i] = 0;
        studentGrade[i] = '\0';
    }
}
void option_5()
{
     cout << "\n\nDELETE MARK MENU\n\n";
     cout << "Enter your student ID: ";
     cin >> id;
     bool found = false;
for(int i = 0; i < MaxSize; i++)
{
   if( studentID[i] == id)
   {
        found = true;
        // now delete the rows in all arrays
        studentID[i] = "";
        studentMark[i] = 0;
        studentGrade[i] = '\0';
    }
}

} //end function

is that right? :S


is that right? :S

Hard to say since we don't have the program spec. But my guess is no. You have (or had) a variable called actualNum that keeps track of how many records there are. I don't see it adjusted here.

You've had two threads merged into one, the questions you have now appear to be different from the ones from the original threads, you very likely have had numerous revisions since the original postings, and the thread is on its third page, so people who haven't commented yet are very unlikely to look at this thread. Given all that, my suggestion would be to mark this thread solved, start a new thread, and post the new updated code, explain what part you're working on, give an overall 5- or 6-sentence description of what the program is supposed to do, what it actually does, etc., and what the problem is.

Okay. I'll copy the assessment task outlines and paste it on here so you may read it then you might understand what I was trying to develop the program.

Two (5th and 6th) options in the bottom code program, they are corresponding to the Part Two, which I haven't finish them yet.

PART-I:
The Basic Program (12 marks)
You are required to design a program gradeStats.cpp that will be used to calculate the average of the student marks for a given class. This program will be menu driven, and the user should be able to interactively enter the student IDs and marks, display the marks for a given student, and calculate the statistics as required.
The basic program should produce a main menu similar to the following
MAIN MENU
0. Exit 1. Statistics
2. Enter mark 3. Find mark

in which the user will enter an integer number to select the corresponding menu item, and once the task associated with the menu item is completed, the program control returns to the main menu. The menu will not accept any other input for the menu selection and will warn on the invalid input as well. The program terminates when Exit is selected. The program behaviour for the menu items is summarised below.
• Exit: The program terminates.
• Statistics: The total number of student marks and the average of those marks will be calculated and displayed.
• Enter mark: The user will be prompted to enter into the program a student ID and the corresponding mark.
• Find mark: The user will be prompted to enter a student ID, and the program will then find and display the corresponding mark.
A student ID is a character string containing no white spaces in it, and the marks can be non-integers. The value of a valid mark is between 0 and 100, and it corresponds to a grade according to
MARKS GRADE
≥ 85 H
≥ 75 but < 85 D
≥ 65 but < 75 C
≥ 50 but < 65 P
< 50 F
Hence if one has the following student ID and mark pairs
S000101 73
S000102 56.5
S000135 88.3
S990001 64.5
S990002 45
S000103 57
then the corresponding grades should be
S000101 73 C
S000102 56.5 P
S000135 88.3 H
S990001 64.5 P
S990002 45 F
S000103 57 P
When Enter mark is selected from the main menu, if the student ID supplied by the user already exists in the records, i.e. entered by the user earlier on, then the program will not try to read the corresponding mark and will abort this action and return to the main menu. This part will be enhanced in Part-II of this assignment.
When Find mark is selected, the user will enter a student ID and the program will then locate the mark corresponding to the given ID and display the record.
For the solution of this part, the students are required to provide
• the defining diagram (IPO diagram) - 2 marks
• the structure chart (hierarchy chart) - 2 marks
o The structure chart must be consistent with the C++ program implemented for this Part-I.
• solution algorithm in pseudocode (don't use the C++ constructs: no break, no return statements for instance) - 3 marks
o Pseudocode details just need to be written for the menu and the marks statistics, while other modules/functions such as readRecord (read in a pair of student ID and mark) and displayRecord (display the mark and grade for a given student ID), or similarly meaningful modules, can be called directly in your pseudocode without having to write the program logic details for such modules. You need to just specify the module name and the passed parameters.
o It is however anticipated that your pseudocode will contain details at least for the MAINLINE module and another module for the actual calculation of the marks average.
o For this part, students may assume that all data that are fed to the program will be in correct format.
• complete program in C++ (including naming, style etc) - 3 marks
o All functionalities described by the main menu should be implemented.
o The program should contain precisely the following two student records when the program is started for execution:
o P1001 78.50
o P1002 66
• general design quality, error reporting, feel and robustness - 2 marks

*************************

PART-II:
The Full Program (3 marks)
The purpose of this part is to extend and polish that basic program described in Part I. The functionality of this extended C++ program, xGradeStats.cpp, should contain the following additional features.
• The main menu should be extended to something similar to
• MAIN MENU
• 0. Exit 1. Statistics 2. Enter mark
• 3. Find mark 4. Delete mark 5. List marks
• The Enter mark functionality should be enhanced as follows. If the student ID for the mark to enter has already got a record in the program (i.e. read by the program earlier on, but not subsequentally deleted), then the newly entered mark will replace the previous mark corresponding to the student ID. This is essentially an update of the student mark. Otherwise, the program simply stores the student ID and the mark as specified for the basic program in Part-I.
• The new menu item Delete mark will get a student ID from the user and delete the mark for the corresponding student ID.
• The new menu item List marks will display all the student IDs, their corresponding marks and grades line by line, similar to
• STUDENT ID MARK GRADE
• P1001 78.50 D
• P1002 66.00 C
• S2001 89.00 H
For simplicity, there is no need to page the output of such a list. We recall that valid student marks are expected to be between 0 and 100. Hence marks outside the valid scope should be flagged in some way during their display.
• The Statistics functionality should also be enhanced. On top of the average of the marks already done in Part-I, the standard deviation should also be calculated and displayed.
For this purpose, we recall that for a set of n values, x1, x2, x3, ..., xn-1, xn, its average μ (also denoted by an overline like x above the vector name x) or mean and the corresponding standard deviation σ are defined by
μ = ( x1 + x2 + x3 + ... + xn-1 + xn )/n,
σ2 = ( (x1 -μ)2 + (x2 -μ)2 + ... + (xn- μ)2 )/n
For the 6 marks in the above sample list, we have n=6, the average of these 6 marks
μ= (73 + 56.5 + 88.3 + 64.5 + 45 + 57)/6 = 64.05,
and the standard deviation σ=13.7718. If we restrict our attention to only a sublist of all those who got the grade "P":
Q000102 56.5
P990001 64.5
P000103 57
then the number n of the marks is 3, the average μ of these marks and the standard deviation σ are
μ= (56.5 + 64.5 + 57)/3 = 59.33,
σ = ( ((56.5-59.33)2+(64.5-59.33)2+(57-59.33)2)/3 )1/2 = 3.6591.
• The program should be robust and should never crash. It should issue appropriate messages on whether a request has been successful or what has actually been done as a result. For instance, if the user aborts his data entry while trying to enter a student record, the program should acknowledge that. In short, the program should be informative of its behaviour and should achieve a sensible user interacing.
For this part, only the complete C++ program needs to be submitted by the students. The program will be assessed not only for the correct functionality, but also for the good design and proper module decomposition. It also takes into consideration of the program robustness at handling unexpected situations. If this part is only partially completed for certain relevant individual modules (functions), then the driver program (the main( ) function) should be designed to illustrate these modules properly. Please note that the work in Part-II is more challenging but gives less marks, students should not spend much of their time on Part-II if they haven't actually well completed Part-I yet. Also, the marking of this part will be more stringent: a mere inconclusive attempt is unlikely to result in any significant marks if at all.
The marks for this Part-II are allocated as follows.
• enhancement of Enter mark (0.5 mark)
• inclusion of standard deviation in Statistics (0.5 mark)
• functionality of Delete mark (0.5 mark)
• functionality of List marks (0.5 mark)
• design quality, error reporting, informative messages, feel and robustness for this Part-II (1 mark)
Below is a list of screen shots of running a possible implementation. This is just one illustration, and the interface design of your program may well be completely different.
** GradeStats ver 1.0 10/2/2009

MAIN MENU
0. Exit 1. Statistics 2. Enter mark
3. Find mark 4. Delete mark 5. List marks

Your choice ->1
** Mean and standard deviation.

MAIN MENU
0. Exit 1. Statistics 2. Enter mark
3. Find mark 4. Delete mark 5. List marks

-------------
Number of records: 2
Mean or average: 72.25
Standard deviation: 6.25
-------------

Your choice ->2
Enter a Student Record:
Student ID ->S2001
Unit Mark ->89
** New mark entered.

MAIN MENU
0. Exit 1. Statistics 2. Enter mark
3. Find mark 4. Delete mark 5. List marks

-------------
Student ID: S2001
Mark/Grade: 89(H)
-------------

Your choice ->5
** List all marks.

MAIN MENU
0. Exit 1. Statistics 2. Enter mark
3. Find mark 4. Delete mark 5. List marks

-------------
STUDEND ID MARK GRADE
P1001 78.50 D
P1002 66.00 C
S2001 89.00 H
-------------

Your choice ->1
** Mean and standard deviation.

MAIN MENU
0. Exit 1. Statistics 2. Enter mark
3. Find mark 4. Delete mark 5. List marks

-------------
Number of records: 3
Mean or average: 77.83
Standard deviation: 9.40
-------------

Your choice ->3
Find marks for ID ->P1002
** Mark found for ID P1002.

MAIN MENU
0. Exit 1. Statistics 2. Enter mark
3. Find mark 4. Delete mark 5. List marks

-------------
Student ID: P1002
Mark/Grade: 66.00(C)
-------------

Your choice ->0

#include <iostream>
#include <string>
using namespace std;

const int MaxSize = 100;
int actualNum = 8;
string studentID[MaxSize]={"p1001","p1002","s000101","s000102","s000135","s990001","s990002","s000103"};
double studentMark[MaxSize]={78.5, 66, 73, 56.5, 88.3, 64.5, 45, 57};
char studentGrade[MaxSize]={'D', 'C', 'C', 'P', 'H', 'P', 'F', 'P'};

void do_again(),direction(int ans);
void option_1(),option_2(),option_3(),option_4(),option_5(),option_6();
 
int main()
{

     do_again();//call do_again function, say goodbye to main until everything else is done running

     return 0;
}//end function

void do_again()
{
     int ans;//declare ans variable, this will be used OVER AND OVER
     do
     {
          cout << "MAIN MENU\n\n";
          cout << "1. Exit         ";
          cout << "2. Statistics   ";
          cout << "3. Enter mark   \n";
          cout << "4. Find mark    ";
          cout << "5. Delete mark  ";
          cout << "6. List marks\n\n";
          cout << "Please choose a number to enter: ";
               
               cin  >> ans;  
               while (cin.fail())
               {cout << "\nWrong data type. Please re-enter: ";
               cin.clear();
               cin.ignore(80,'\n'); //Take in an answer
               cin>>ans; cout<<endl;
               }
          direction(ans);//Send that answer to direction
     }while(ans!=1);//Keep on keeping on until they press 1 to exit
}//end function

void direction(int ans)
{
     switch (ans)//roll thru options
     {
          case 1:  //if they picked the number 1, its gonna go to this function, 
               option_1();
               break;
          case 2:
               option_2();
               break;
          case 3:
               option_3();
               break;
          case 4:
               option_4();
               break;
          case 5:
               option_5();
               break;
          case 6:
               option_6();
               break;
          default://THEY DID NOT READ THE MENU, WHO WOULD HAVE THOUGHT?
               cout << "\nPlease press 2, 3 or 4. Press 1 for close the menu.\n\n\n";
               //break;
     }
}//end function

//functions, FILL WITH VALUABLE PROGRAMMING SKILLS

void option_1()
{
}//end function

void option_2()
{   
    cout << "\n\nSTATISTICS MENU\n\n";
    cout << "The number of student records is " << actualNum << " and" << endl;
    
    double total;
    float average;
    for (int i = 0; i < MaxSize; ++i)
    {
    total = total + studentMark[i];
    }
    average = (total / actualNum);
    cout << "the average of those student marks is " << average;
    cout << "\n\n";
}//end function

void option_3()
{
         double mark;
         char grade;
         string id;
    cout << "\n\n";
    cout << "ENTER MARK MENU\n\n";
    cout << "Enter the ID: ";
    cin >> studentID[actualNum];
    cout << "Enter the mark: ";
    cin >> mark;
    studentMark[actualNum] = mark;
    if (mark<=100 && mark>=0)
    cout << "This student record is data stored successfully.\n\n\n";
    else
    cout << "This student record you entered is incorrect.\n\n\n";

if (mark<=100 && mark>=0)
{
    if (mark>=85)
    //   cout << "The mark " << mark << " is: H\n\n\n";
    studentGrade[actualNum]='H';
    else if (mark>=75)
	//   cout << "The mark " << mark << " is: D\n\n\n";
	studentGrade[actualNum]='D';
    else if (mark>=65)
	//   cout << "The mark " << mark << " is: C\n\n\n";
	studentGrade[actualNum]='C';
    else if (mark>=50)
	//   cout << "The mark " << mark << " is: P\n\n\n";
	studentGrade[actualNum]='P';
    else
	//  cout << "The mark " << mark << " is: F\n\n\n";
	studentGrade[actualNum]='F';
}
else
	studentGrade[actualNum]='I'; // Error
	
++actualNum;
}//end function

void option_4()
{    
    int i=-1;
     string id;
     cout << "\n\nFIND MARK MENU\n\n";
     cout << "Enter your student ID: ";
     cin >> id;
   
     while(++i<actualNum) {
     if(id==studentID[i])
     {cout << "Your mark is: " << studentMark[i] << " and your grade is: " << studentGrade[i];
     cout << "\n";
     break;}
     }
     if (i==actualNum)
     cout << "Sorry, it is not existing." << endl;
     cout << "\n\n";

} //end function

void option_5()
{

} //end function

void option_6()
{

} // end function

This last post doesn't tell us what the question is. option_5 and option_6 are now blank. They weren't before. Why? What works, what doesn't, what is the precise question? You need to specify a certain block of code that you think is problematic and tell us what it is. Otherwise we're looking through 166 lines. It's also unlikely anyone is going to want to go through the whole spec. You need to SUMMARIZE the part of the spec that is relevant to the particular problem and again, say what the particular problem is. And again, most people who haven't commented yet aren't going to read this thread because it's gotten long. It's best to mark this one solved and start a new one with a specific question.

Option 5, Delete Marks.
Once you have stored information in an array you can't delete it. There, plain and simple. Having said that you can create functionality to make the program act as though the information is deleted. To implement one such algorithm you could use a combination of two strategies, ignoring and overwirting. To make the discussion more concrete I'll use the following information for demonstation purposes.

const int MAX_SIZE = 4; //max number of elements in the array
int indexesToUse = 4; //number of indexes I need to look at in the array
int myArr[MAX_SIZE] = {3, 33, -1, 14};

Printing contents of myArr would usually be done using a loop

for(int a = 0; a < indexesToUse;  ++a)
{
  cout << myArr[a] << ' ';
}

Now let's say I want to "delete" the value of -1 from the array because I only want the array to contain positive integers. I could pretend I've deleted it if I ignore all negative numbers in myArray when using (in this case, printing) the contents of myArr by doing something like this:

for(int a = 0; a < indexesToUse;  ++a)
{
   if(myArr[a] >= 0)  //ignore negative integers
   {
      cout << myArr[a] << ' ';
   }
}

If you have a convenient separating characteristic this can work well. Now let's say the value of 33 should be "deleted". You could write an inclusive ignore statement like:

if(myArr[a] >= 0 && myArr[a] != 33)

but that will get clumsy fast. So to keep just a simple ignore statment I could find the value of 33 and overwrite it with a negative value.

for(int a = 0; a < indexesToUse; ++a)
{
    if(myArr[a] == 33])
    {
      myArr[a] = -99;
    }
}

for(int a = 0; a < indexesToUse;  ++a)
{
   if(myArr[a] >= 0)
   {
      cout << myArr[a] << ' ';
   }
}

Notice that so far I have had to look at all elements of myArr to determine whether it should be ignored (effectively deleting it) or not. You can "overcome" this ineffieciency by introducing another one. That is, instead of simply ignoring a value to "delete" because it has some default value, you can shift all values that have a higher index than the desired value to the left by one (which is an inefficient process). This effectively "deletes" the desired value but creates a duplicate value "at the end" that will then be ignored. To illlustrate this lets start with the original values of myArr as introduced above and lets delete the value of 33 by overwriting by shifting to the left by one the values of all the elements with indexes to right of the index of the element whose value is 33.

//find the index of the element you want to delete
int deleteThisIndex;
for(int a = 0; a < indexesToUse; ++a)
{
    if(myArr[a] == 33])
    {
       deleteThisIndex = a;
    }
}

//shift elements to right of deleteThisIndex to the left by one
for(int a = deleteThisIndex; a < indexesToUse - 1; ++a)
{
   myArr[a] = myArr[a + 1];
}
//note that the last valid index won't be overwritten with this loop!

//print the values in myArr
for(int a = 0; a < indexesUsed;  ++a)
{
    cout << myArr[a] << ' ';
}
}

The output should be: 3, -1, 14, 14.......effectively deleting the value of 33 from myArr but duplicaing the value of 14 at the end. That wasn't the intended effect. To use just the first three values in myArr, which is all I want to "keep" after "deleting" the value of 33, the value of indexesToUse can be decremented by one before using the array again after the shift, thus ignoring the last value of myArr eventhough it is still there.

Note that there are always MAX_SIZE ints in myArr. If I don't initialize the ints (elements if you prefer) then the values of the ints(elements) are junk, but the ints are there nonetheless. Likewise, I can't delete an int in myArr, but I can ignore a given element based on some criteria, thereby producing the effect of deleting an element.

A completely different approach would be to declare a new array with one less element than the original and assign all the elements from the original array but the one you want to delete into new array. Again, you haven't deleted an element of an array since you have created an entirely new array which doesn't contain the one you wanted deleted from the original.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Comments
Thorough explanation.

Option 5, Delete Marks.
Once you have stored information in an array you can't delete it. There, plain and simple.

If it's systematically and effectively no longer part of the data being looked at, it seems to me that it's "deleted", at least in a loose definition of the word, or at least that it doesn't matter whether it's deleted or not. You refer to making it act like it's been deleted, which I think is good enough here. You listed some ways of doing that. The address is still reserved as part of the array, if that's what you mean by it not being deleted.

You can "overcome" this ineffieciency by introducing another one. That is, instead of simply ignoring a value to "delete" because it has some default value, you can shift all values that have a higher index than the desired value to the left by one (which is an inefficient process). This effectively "deletes" the desired value

I was thinking along these lines. If you want a contiguous array where you don't have to ignore anything, I can't think of another way.

but creates a duplicate value "at the end" that will then be ignored.

You deal with this effectively below. You can also overwrite the value to some sentinel value or some other value that represents a value that cannot be legitimate data (i.e. -99999999) for this purpose.

the value of indexesToUse can be decremented by one before using the array after the shift, thus ignoring the last value of myArr.

This is the idea. The OP has this value set up. Why not use it? It doesn't matter what's in the array beyond the data that you care about.

A completely different approach would be to declare a new array with one less element than the original and assign all the elements from the original array but the one you want to delete into new array. Again, you haven't deleted an element of an array since you have created an entirely new array which doesn't contain the one you wanted deleted from the original.

I don't see the advantage of this method over your previous method. It's going to take at least as long and much likely longer to create the new array, and it adds unnecessary complexity to the code.

This article has been dead for over six months. Start a new discussion instead.