student report program

I will be very a happy if anyone can assist me


Suppose we want to compile a student academic report for a high school learner in grade 12 (matric).
A matric learner is enrolled for 6 study units (subjects), namely: English, Mathematics, Life Orientation,
History, Computer literacy, Geography. The learner has to pass at least four subjects, including English,
to complete grade 12. The subject pass mark is 50%.

Write a program that prompts the learner to key in their marks for each subject. The program should
include the following functions:
a. A function studentDetails, that prompts the learner to key in their personal details
name,surname, and schoolName.
b. A function getMarks, that prompts the learner to key in a mark for each of the six subjects, and
validate the marks. Do not accept marks lower than 0 or higher than 100.
c.A function calcAverageYearMark, to calculate and display the average of the 6 Subjects. This function should be called just once by main, and should be passed the 6 Subject marks.
d.A function minMax, to find and return the lowest and the highest of the 6 subject marks passed to it as the subject with the lowest mark;
e. A function passOrFail, to determine whether the student has passed or failed grade 12.
f. A function awardDistinction to determine which of the subjects have received
distinctions. A subject receives a distinction if the mark is 75% and above. Also a student
has passed with distinction if the average mark is 75% and above.

g. A function codeSymbol, to convert each mark to a symbol (A, B, C, D, E, F) and a code
(7,6,5,4,3,2,1). The symbol and code should be printed next to the mark in the student
report.
The same should be calculated and displayed for the average mark.
h.A function to Display the student report.






#include <iostream>

using namespace std;
double marks [6];

int minMax(double marks[6]) /*Question 2d*/

{
double max;
double min;
double minIndex;
double maxIndex;
for (int i = 0; i < 6; ++i)
{
max = 0;
if (marks[i] > max)
{
marks[i] = max;
maxIndex = i;
}

}

for (int i = 0; i < 6; ++i)
{
min = 0;
if (marks[i] < min )
{
marks[i] = min;
minIndex = i;
}

}
cout << "Your lowest mark was " << marks[minIndex] << endl;
cout << "Your highest mark is for " << marks[maxIndex] << endl;

}

int calcAverageYearMark(double eng, double math,double lo,double hist,double clit,double art) /*Question 2c*/
{
double totMark;
double avgMark;


totMark = marks[0] + marks[1] + marks[2] + marks[3] + marks[4] + marks[5];
avgMark = totMark / 6;

cout << "Your averge mark is " << avgMark << endl;
}

int getMarks(double eng, double math,double lo,double hist,double clit,double art) /*Question 2b*/
{


cout << "Key in your mark for English: ";
cin >> eng;
cout << "Key in your mark for Mathematics: ";
cin >> math;
cout << "Key in your mark for Life Orientation: ";
cin >> lo;
cout << "Key in your mark for History: ";
cin >> hist;
cout << "Key in your mark for Computer Literacy: ";
cin >> clit;
cout << "Key in your mark for Art: ";
cin >> art;

marks [0] = eng;
marks [1] = math;
marks [2] = lo;
marks [3] = hist;
marks [4] = clit;
marks [5] = art;
}


int studentDetails( string name, string school ) /*Question 2a*/

{
cout << "Please key in your name: ";
cin >> name;


cout << "Please key in the name of your school: \n";
cin >> school;


/*cout << "Your weight is " << name << endl;
cout << "Your height is " << school << endl;*/



}


int main()
{

string name;
string school;
double eng;
double math;
double lo;
double hist;
double clit;
double art;


studentDetails(name,school);
getMarks(eng,math,lo,hist,clit,art);
calcAverageYearMark( eng,math,lo,hist,clit,art);
minMax(marks);
return 0;

}
Last edited on
Please use https://www.cplusplus.com/articles/jEywvCM9/ when posting code.
So it looks something like this.
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
#include <iostream>
using namespace std;

double marks[6];

int minMax(double marks[6])
{                               /*Question 2d */
  double max;
  double min;
  double minIndex;
  double maxIndex;
  for (int i = 0; i < 6; ++i) {
    max = 0;
    if (marks[i] > max) {
      marks[i] = max;
      maxIndex = i;
    }
  }

  for (int i = 0; i < 6; ++i) {
    min = 0;
    if (marks[i] < min) {
      marks[i] = min;
      minIndex = i;
    }
  }
  cout << "Your lowest mark was " << marks[minIndex] << endl;
  cout << "Your highest mark is for " << marks[maxIndex] << endl;

}

int calcAverageYearMark(double eng, double math, double lo, double hist, double clit, double art)
{                               /*Question 2c */
  double totMark;
  double avgMark;

  totMark = marks[0] + marks[1] + marks[2] + marks[3] + marks[4] + marks[5];
  avgMark = totMark / 6;

  cout << "Your averge mark is " << avgMark << endl;
}

int getMarks(double eng, double math, double lo, double hist, double clit, double art)
{                               /*Question 2b */
  cout << "Key in your mark for English: ";
  cin >> eng;
  cout << "Key in your mark for Mathematics: ";
  cin >> math;
  cout << "Key in your mark for Life Orientation: ";
  cin >> lo;
  cout << "Key in your mark for History: ";
  cin >> hist;
  cout << "Key in your mark for Computer Literacy: ";
  cin >> clit;
  cout << "Key in your mark for Art: ";
  cin >> art;

  marks[0] = eng;
  marks[1] = math;
  marks[2] = lo;
  marks[3] = hist;
  marks[4] = clit;
  marks[5] = art;
}


int studentDetails(string name, string school)
{                               /*Question 2a */
  cout << "Please key in your name: ";
  cin >> name;
  cout << "Please key in the name of your school: \n";
  cin >> school;

/*cout << "Your weight is " << name << endl;
cout << "Your height is " << school << endl;*/
}


int main()
{
  string name;
  string school;
  double eng;
  double math;
  double lo;
  double hist;
  double clit;
  double art;

  studentDetails(name, school);
  getMarks(eng, math, lo, hist, clit, art);
  calcAverageYearMark(eng, math, lo, hist, clit, art);
  minMax(marks);
  return 0;
}


Next, compile with lots of warnings enabled.
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
$ g++ -Wall -Wextra -Wshadow foo.cpp
foo.cpp: In function ‘int minMax(double*)’:
foo.cpp:6:27: warning: declaration of ‘marks’ shadows a global declaration [-Wshadow]
 int minMax(double marks[6])
                           ^
foo.cpp:4:8: note: shadowed declaration is here
 double marks[6];
        ^
foo.cpp:27:52: error: invalid types ‘double*[double]’ for array subscript
   cout << "Your lowest mark was " << marks[minIndex] << endl;
                                                    ^
foo.cpp:28:56: error: invalid types ‘double*[double]’ for array subscript
   cout << "Your highest mark is for " << marks[maxIndex] << endl;
                                                        ^
foo.cpp:30:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
foo.cpp: In function ‘int calcAverageYearMark(double, double, double, double, double, double)’:
foo.cpp:41:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
foo.cpp: At global scope:
foo.cpp:32:32: warning: unused parameter ‘eng’ [-Wunused-parameter]
 int calcAverageYearMark(double eng, double math, double lo, double hist, double clit, double art)
                                ^
foo.cpp:32:44: warning: unused parameter ‘math’ [-Wunused-parameter]
 int calcAverageYearMark(double eng, double math, double lo, double hist, double clit, double art)
                                            ^
foo.cpp:32:57: warning: unused parameter ‘lo’ [-Wunused-parameter]
 int calcAverageYearMark(double eng, double math, double lo, double hist, double clit, double art)
                                                         ^
foo.cpp:32:68: warning: unused parameter ‘hist’ [-Wunused-parameter]
 int calcAverageYearMark(double eng, double math, double lo, double hist, double clit, double art)
                                                                    ^
foo.cpp:32:81: warning: unused parameter ‘clit’ [-Wunused-parameter]
 int calcAverageYearMark(double eng, double math, double lo, double hist, double clit, double art)
                                                                                 ^
foo.cpp:32:94: warning: unused parameter ‘art’ [-Wunused-parameter]
 int calcAverageYearMark(double eng, double math, double lo, double hist, double clit, double art)
                                                                                              ^
foo.cpp: In function ‘int getMarks(double, double, double, double, double, double)’:
foo.cpp:64:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
foo.cpp: In function ‘int studentDetails(std::__cxx11::string, std::__cxx11::string)’:
foo.cpp:76:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^


> error: invalid types ‘double*[double]’ for array subscript
Your array subscripts must be integers.
1
2
3
4
5
6
int minMax(double marks[6])
{                               /*Question 2d */
  double max;
  double min;
  double minIndex;  //<<< These!
  double maxIndex;


> warning: declaration of ‘marks’ shadows a global declaration [-Wshadow]
Your parameter name matches a global variable. It can lead to confusion later on.
It would be much better if you declared the array in main and passed it around as a parameter.

> foo.cpp:32:32: warning: unused parameter ‘eng’ [-Wunused-parameter]
There's no point passing parameters if you never use them.

> warning: no return statement in function returning non-void [-Wreturn-type]
You never return a value, and you never try to use the result either. So make them void functions.

An array type error, as I see it. Must be a different type, Integer. In general, I saw a similar job on the site alone, find at https://phdessay.com/free-essays-on/global-warming/ will suddenly help you with some of the finished code from there, it's free. There are a lot of students, maybe someone will borrow your task
Last edited on
I great technique for doing assignments like this is to copy the list items into the code as comments. This helps you make sure that you're doing everything requested. Building on salemC's code:
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
124
125
126
127
128
129
130
131
132
133
#include <iostream>
using namespace std;

double marks[6];




// d.A function minMax, to find and return the lowest and the highest
//   of the 6 subject marks passed to it as the subject with the lowest
//   mark;
int minMax(double marks[6])
{                               /*Question 2d */
  double max;
  double min;
  double minIndex;
  double maxIndex;
  for (int i = 0; i < 6; ++i) {
    max = 0;
    if (marks[i] > max) {
      marks[i] = max;
      maxIndex = i;
    }
  }

  for (int i = 0; i < 6; ++i) {
    min = 0;
    if (marks[i] < min) {
      marks[i] = min;
      minIndex = i;
    }
  }
  cout << "Your lowest mark was " << marks[minIndex] << endl;
  cout << "Your highest mark is for " << marks[maxIndex] << endl;

}

// c.A function calcAverageYearMark, to calculate and display the
// average of the 6 Subjects. This function should be called just once
// by main, and should be passed the 6 Subject marks.
int calcAverageYearMark(double eng, double math, double lo, double hist, double clit, double art)
{                               /*Question 2c */
  double totMark;
  double avgMark;

  totMark = marks[0] + marks[1] + marks[2] + marks[3] + marks[4] + marks[5];
  avgMark = totMark / 6;

  cout << "Your averge mark is " << avgMark << endl;
}

// b. A function getMarks, that prompts the learner to key in a mark for each of the six subjects, and
// validate the marks. Do not accept marks lower than 0 or higher than 100.
int getMarks(double eng, double math, double lo, double hist, double clit, double art)
{                               /*Question 2b */
  cout << "Key in your mark for English: ";
  cin >> eng;
  cout << "Key in your mark for Mathematics: ";
  cin >> math;
  cout << "Key in your mark for Life Orientation: ";
  cin >> lo;
  cout << "Key in your mark for History: ";
  cin >> hist;
  cout << "Key in your mark for Computer Literacy: ";
  cin >> clit;
  cout << "Key in your mark for Art: ";
  cin >> art;

  marks[0] = eng;
  marks[1] = math;
  marks[2] = lo;
  marks[3] = hist;
  marks[4] = clit;
  marks[5] = art;
}


// a. A function studentDetails, that prompts the learner to key in their personal details
// name,surname, and schoolName.
int studentDetails(string name, string school)
{                               /*Question 2a */
  cout << "Please key in your name: ";
  cin >> name;
  cout << "Please key in the name of your school: \n";
  cin >> school;

/*cout << "Your weight is " << name << endl;
cout << "Your height is " << school << endl;*/
}

// e. A function passOrFail, to determine whether the student has passed or failed grade 12.
void passOrFail()		// actual signature TBD
{
}

// f. A function awardDistinction to determine which of the subjects have received
// distinctions. A subject receives a distinction if the mark is 75% and above. Also a student
// has passed with distinction if the average mark is 75% and above.
void awardDistinction()		// actual signature TBD
{
}

// g. A function codeSymbol, to convert each mark to a symbol (A, B, C, D, E, F) and a code
// (7,6,5,4,3,2,1). The symbol and code should be printed next to the mark in the student
// report.
// The same should be calculated and displayed for the average mark.
void codeSymbol()		// actual signature TBD
{
}

// h.A function to Display the student report.
void Display()			// actual signature TBD
{
}


int main()
{
  string name;
  string school;
  double eng;
  double math;
  double lo;
  double hist;
  double clit;
  double art;

  studentDetails(name, school);
  getMarks(eng, math, lo, hist, clit, art);
  calcAverageYearMark(eng, math, lo, hist, clit, art);
  minMax(marks);
  return 0;
}


Now look at each function and try to determine it's arguments, return value and basic function. Right away some questions come to my mind:
- minMax() is supposed to return the lowest and the highest values. So you need to return a struct containing both values or maybe pass in the min and max values by reference.

- minMax() takes the 6 subjects in an array, but getMarks() takes them individually. You should be consistent. Personally, I'd use an array, and have your program define const ints or an enum for the indices of the subjects. E.g.:
1
2
// Array indices for the different subjects
enum { English, Math, Life, History, Computer, Geography };


- Why does studentDetails return an int? What int would it return? Also, you're passing the name and school by value, so the function won't modify the actual parameters passed in.

Let's look at how to determine the signature of the remaining functions. Take passOrFail as an example:
e. A function passOrFail, to determine whether the student has passed or failed grade 12.
It returns a yes/no, or either/or value, so let's return a bool. Also, it needs to examine all the grades, so pass the grades in. That gives is:
1
2
// Return true/false if the student passes/fails grade 12.
bool passFail(int grades[6]);


Do the same for awardDistinction(), codeSymbol and Display(). You may find that some of these are tricky.

Once you're done, implement and test the functions one at a time. You'll find it much easier because you'll always be working on a small part of the code. Also it's more satisfying because you'll make steady, noticeable progress.
Topic archived. No new replies allowed.