Write a C++ program ,that uses modularisation.
The program allows the end user to enter a test mark which is converted into persantage by a particular funtion, the test mark is returned to main(),
another funtion is called which detemines whether the student passed or failed if ist a pass increment number of students who passed do like wise for fail, the funtion must also determine the average pass rate and average fail rate.
The last funtion displays the results in a tabular format,
it displays the total number of students ,number of failures ,num,ber of passes and there averages.

#include <iostream>
using namespce std;
void ReadInput();   //this funtion allows the user to enter the test mark.
{
  duoble marks;   //student mark
  mark *=0.5 //mark converted to persantage if the test is out of 50.
  cout<<"ENTER STUDENT MARK"<<endl;
  cin>>mark;
  return mark;
}
double calulateResults(double);
void showResults(doule);
int main()
{
    readInput();
    while(mark !=-999){
         calculateResults(mark);
         showResults(double);
         readInput();
         }
     return 0;
}
calculateResults(double mark)
{
    double mark;



double calculateResults(double); //this

Edited 3 Years Ago by Dani: Formatting fixed

Hi Maponya, this is Lerroy and I would like to have your permission to see if this program can run because I'm also suffering from its difficult situation.HELP PLZ...

Edited 3 Years Ago by happygeek: fixed formatting

k .. continue what u r doing ?? what is the other fucktion that u want .. and write it .. i dont see any something hard in this code ..
if u have say where r u stuck ??

look at this program ... and try to develop it to satisfy ur needs

Attachments
/*********************************

___ grader program ___
inputs a classes quiz scores,
creating a structure for each
unique student id, then average
the grade and sorting final student
grades from high to low.

**********************************/


#include <stdio.h>

#define 	MAXSTUDENTS 	25


/*GLOBALS*/

int	totalStudents;


struct studentrec {
	int q1,
		q2,
		q3,
		id,
		avg;
	char grade;
}	 studentRecordsStructure[MAXSTUDENTS];


int checkID( int temp ) {

	int myBool, y;
	myBool = 1;

	printf("                verifying unique ID....");
	for (y = 0; y < totalStudents; y++){
		/*printf("\n comparing to %d..\n", studentRecordsStructure[y].id);
		//question : why does studentRecordsStructure[y] appear as zero when printed? */
		if (temp == studentRecordsStructure[y].id) {
			printf("\nthe ID \"%d\" is taken. try another. >", temp);
			return myBool;
		}
	}

	myBool = 0; /* if it gets this far, there is no match with another ID */
	printf("  ID %d accepted.\n", temp);
	return myBool;
}


void get_a_rec( struct studentrec *student ) {

	int temp, boolean;
	boolean = 1;

	printf("\n please enter student ID : ");

    do {
		scanf ("%d", &student->id);
		boolean = checkID(student->id);
	} while (boolean == 1);

	printf(" :: quiz 1 :: ");
	scanf ("%d", &student->q1);
	printf(" :: quiz 2 :: ");
	scanf ("%d", &student->q2);
	printf(" :: quiz 3 :: ");
	scanf ("%d", &student->q3);
}


int average ( struct studentrec student ) {
	int sum = 0;
	sum = student.q1 + student.q2 + student.q3;
	return sum / 3;
}


char letter_grade ( int score ) {
	if	 	(score	>=	90) return 'A';
	else if (score	>=	80) return 'B';
	else if (score	>=	70) return 'C';
	else if (score	>=	60) return 'D';
	else					return 'F';
}


void getStudentRecords() {

	int i, cont;

	cont = 0;
	totalStudents = 0;

	do{
		printf("\n\nHow many students are in your class? (MAX = 25) > ");
		scanf ("%d", &totalStudents);
		if ( (totalStudents <= MAXSTUDENTS) && ( totalStudents > 0 ) ) { cont = 1; }
	} while (cont == 0);

	for (i = 0; i < totalStudents; i++) {

		struct studentrec st1;
		get_a_rec ( &st1 );
		st1.avg = average( st1 );
		st1.grade = letter_grade ( st1.avg );
		studentRecordsStructure[i]= st1; /* puts this student into array
											of "students" structure */
	}
}


void sortStudentRecords() {

	int u, v;

	struct studentrec sortTemp;

	for ( u = 0; u < (totalStudents - 1); u++) {
		for ( v = 0; v < (totalStudents - (u + 1)); v++) {
			if ( studentRecordsStructure[v].avg < studentRecordsStructure[v+1].avg ) {
				sortTemp = studentRecordsStructure[v];
				studentRecordsStructure[v] = studentRecordsStructure[v+1];
				studentRecordsStructure[v+1] = sortTemp;
			}
		}
	}
}


void printStudentRecords() {

	int j;
	printf(" \n\n");
	printf("  ID____Q1____Q2____Q3____AVG___LTR_\n");
	for (j = 0; j < totalStudents; j++) {
		printf(" %3d ..%3d . %3d . %3d .. %3d . %3c \n",
		    studentRecordsStructure[j].id,
		    studentRecordsStructure[j].q1,
		    studentRecordsStructure[j].q2,
		    studentRecordsStructure[j].q3,
		    studentRecordsStructure[j].avg,
		    studentRecordsStructure[j].grade);
	} printf("\nciao.\n\n");
}


main() {

	getStudentRecords();
	sortStudentRecords();
	printStudentRecords();

}

I'm Lerroy and this is how I've approached Maponya's Challenging problem.

#include<iostream>   

#include<iomanip> 

using namespace std;   //program uses std;

double readInput();  //function prototype

void calculatetotals(double,double &,int &,double &,int &); //function prototype

void showresults(double,int,double,int);   //function prototype

void starlines(void);  //function prototype

void main()
{
 double put=0;

double failmark=0;  //fail mark

double passmark=0;  //pass mark

int fail=0;  //failing students

int pass=0;  //passing students


 put=readInput();
 
 while put!=-999)
 {
  calculatetotals(put,passmark,pass,failmark,fail);

  put=readInput();
 }
 showresults(passmark,pass,failmark,fail);
  return;
}
 

double readInput()
{
 double mark;

 cout<<"\nEnter student mark,-999 to stop : ";  //prompt for student mark

 cin>>mark;  //reads mark

 //the mark must not b = -999,musn't b -(<0) and musn't b >100(total mark).
 
 while((mark!=-999 && mark<0)||mark>100)
 {
  cout<<"\nI think the test was out of 100..."<<endl; //if the user enters mark>50.

  cout<<"\nStudent mark again please: ";  //if wrong mark is entered

     cin>>mark; //reads mark
 }
 return mark;
}


void calculatetotals(double mark,double &passmark,int &pass,double &failmark,int &fail)
    
{
  if(mark>=0 && mark<50) // for students who failed(got below 50)
  {
   fail++;  //failed students.
      failmark+=mark; //fail  mark.
  }
  if(mark>=50 && mark<=100)  //for students who passed(got 50 and above ).
  {
   pass++;  //passed students.
   passmark+=mark;  //pass mark.
  }
}


void showresults(double Passmark,int Pass,double Failmark,int Fail)
{
   cout<<fixed<<setprecision(2);  //formatting the data type

   cout<<endl;

   cout<<"No. of students in a class   : "<<Pass+Fail<<endl;  //students in class

   cout<<"\n\t\tResults :"<<endl;

   starlines(); //call function starlines()

   if(Pass!=0)   //if pass = 0,is not calculated(average).
   {
    cout<<"\tPassed students : "<< Pass <<endl;
   }
   if(Fail!=0)  //if fail = 0,is not calculated(average).
   {
    cout<<"\tFailed students : "<< Fail <<endl;
   }
   
   starlines();  //call function starlines()

   cout<<"\n\t\tAverages :"<<endl;
   
   starlines();   //call function starlines()

   if(Pass != 0)
   {
    cout<<"\tPass average :"<<(Passmark/Pass)<<endl;
   }
   if(Fail != 0)
   {
    cout<<"\tFail average :"<<(Failmark/Fail)<<endl;
   }
   starlines();   //call function starlines()
   cout << endl;

}
    //definition of the function starline.
     void starlines(void)
  {
   cout <<"\t*\a*\a*\a**************\a*\a*\a"<<endl;

   cout <<endl;
  }

well i think that this is correct but what i have face it that the program shut down automaticaly without seeing the result

#include<iostream> 

#include<iomanip> 

using namespace std; //program uses std;

double readInput(); //function prototype

void calculatetotals(double,double &,int &,double &,int &); //function prototype

void showresults(double,int,double,int); //function prototype

void starlines(void); //function prototype

int main()
{
double put=0;

double failmark=0; //fail mark

double passmark=0; //pass mark

int fail=0; //failing students

int pass=0; //passing students


put=readInput();

while (put!=-999)
{
calculatetotals(put,passmark,pass,failmark,fail);

put=readInput();
}
showresults(passmark,pass,failmark,fail);
return 0;
}


double readInput()
{
double mark;

cout<<"\nEnter student mark,-999 to stop : "; //prompt for student mark

cin>>mark; //reads mark

//the mark must not b = -999,musn't b -(<0) and musn't b >100(total mark).

while((mark!=-999 && mark<0)||mark>100)
{
cout<<"\nI think the test was out of 100..."<<endl; //if the user enters mark>50.

cout<<"\nStudent mark again please: "; //if wrong mark is entered

cin>>mark; //reads mark
}
return mark;
}


void calculatetotals(double mark,double &passmark,int &pass,double &failmark,int &fail)

{
if(mark>=0 && mark<50) // for students who failed(got below 50)
{
fail++; //failed students.
failmark+=mark; //fail mark.
}
if(mark>=50 && mark<=100) //for students who passed(got 50 and above ).
{
pass++; //passed students.
passmark+=mark; //pass mark.
}
}


void showresults(double Passmark,int Pass,double Failmark,int Fail)
{
cout<<fixed<<setprecision(2); //formatting the data type

cout<<endl;

cout<<"No. of students in a class : "<<Pass+Fail<<endl; //students in class

cout<<"\n\t\tResults :"<<endl;

starlines(); //call function starlines()

if(Pass!=0) //if pass = 0,is not calculated(average).
{
cout<<"\tPassed students : "<< Pass <<endl;
}
if(Fail!=0) //if fail = 0,is not calculated(average).
{
cout<<"\tFailed students : "<< Fail <<endl;
}

starlines(); //call function starlines()

cout<<"\n\t\tAverages :"<<endl;

starlines(); //call function starlines()

if(Pass != 0)
{
cout<<"\tPass average :"<<(Passmark/Pass)<<endl;
}
if(Fail != 0)
{
cout<<"\tFail average :"<<(Failmark/Fail)<<endl;
}
starlines(); //call function starlines()
cout << endl;

}
//definition of the function starline.
void starlines(void)
{
cout <<"\t*\a*\a*\a**************\a*\a*\a"<<endl;

cout <<endl;
}
This article has been dead for over six months. Start a new discussion instead.