943,772 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3772
  • C++ RSS
Jul 30th, 2004
0

fUNTIONS

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MAPONYA is offline Offline
3 posts
since Jul 2004
Jul 30th, 2004
0

Re: fUNTIONS

#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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MAPONYA is offline Offline
3 posts
since Jul 2004
Aug 2nd, 2004
0

Re: fUNTIONS

Quote originally posted by MAPONYA ...
#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
7b

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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lerroy is offline Offline
2 posts
since Aug 2004
Aug 2nd, 2004
0

Re: fUNTIONS

k .. continue what u r doing ?? what is the other ****tion that u want .. and write it .. i dont see any something hard in this code ..
if u have say where r u stuck ??
Team Colleague
Reputation Points: 55
Solved Threads: 3
Junior Poster
meabed is offline Offline
139 posts
since May 2004
Aug 2nd, 2004
0

Re: fUNTIONS

look at this program ... and try to develop it to satisfy ur needs
Attached Files
File Type: c hw2_ron_goldin.c (3.1 KB, 17 views)
Team Colleague
Reputation Points: 55
Solved Threads: 3
Junior Poster
meabed is offline Offline
139 posts
since May 2004
Aug 10th, 2004
0

Re: fUNTIONS

I'm Lerroy and this is how I've approached Maponya's Challenging problem.
C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2.  
  3. #include<iomanip>
  4.  
  5. using namespace std; //program uses std;
  6.  
  7. double readInput(); //function prototype
  8.  
  9. void calculatetotals(double,double &,int &,double &,int &); //function prototype
  10.  
  11. void showresults(double,int,double,int); //function prototype
  12.  
  13. void starlines(void); //function prototype
  14.  
  15. void main()
  16. {
  17. double put=0;
  18.  
  19. double failmark=0; //fail mark
  20.  
  21. double passmark=0; //pass mark
  22.  
  23. int fail=0; //failing students
  24.  
  25. int pass=0; //passing students
  26.  
  27.  
  28. put=readInput();
  29.  
  30. while put!=-999)
  31. {
  32. calculatetotals(put,passmark,pass,failmark,fail);
  33.  
  34. put=readInput();
  35. }
  36. showresults(passmark,pass,failmark,fail);
  37. return;
  38. }
  39.  
  40.  
  41. double readInput()
  42. {
  43. double mark;
  44.  
  45. cout<<"\nEnter student mark,-999 to stop : "; //prompt for student mark
  46.  
  47. cin>>mark; //reads mark
  48.  
  49. //the mark must not b = -999,musn't b -(<0) and musn't b >100(total mark).
  50.  
  51. while((mark!=-999 && mark<0)||mark>100)
  52. {
  53. cout<<"\nI think the test was out of 100..."<<endl; //if the user enters mark>50.
  54.  
  55. cout<<"\nStudent mark again please: "; //if wrong mark is entered
  56.  
  57. cin>>mark; //reads mark
  58. }
  59. return mark;
  60. }
  61.  
  62.  
  63. void calculatetotals(double mark,double &passmark,int &pass,double &failmark,int &fail)
  64.  
  65. {
  66. if(mark>=0 && mark<50) // for students who failed(got below 50)
  67. {
  68. fail++; //failed students.
  69. failmark+=mark; //fail mark.
  70. }
  71. if(mark>=50 && mark<=100) //for students who passed(got 50 and above ).
  72. {
  73. pass++; //passed students.
  74. passmark+=mark; //pass mark.
  75. }
  76. }
  77.  
  78.  
  79. void showresults(double Passmark,int Pass,double Failmark,int Fail)
  80. {
  81. cout<<fixed<<setprecision(2); //formatting the data type
  82.  
  83. cout<<endl;
  84.  
  85. cout<<"No. of students in a class : "<<Pass+Fail<<endl; //students in class
  86.  
  87. cout<<"\n\t\tResults :"<<endl;
  88.  
  89. starlines(); //call function starlines()
  90.  
  91. if(Pass!=0) //if pass = 0,is not calculated(average).
  92. {
  93. cout<<"\tPassed students : "<< Pass <<endl;
  94. }
  95. if(Fail!=0) //if fail = 0,is not calculated(average).
  96. {
  97. cout<<"\tFailed students : "<< Fail <<endl;
  98. }
  99.  
  100. starlines(); //call function starlines()
  101.  
  102. cout<<"\n\t\tAverages :"<<endl;
  103.  
  104. starlines(); //call function starlines()
  105.  
  106. if(Pass != 0)
  107. {
  108. cout<<"\tPass average :"<<(Passmark/Pass)<<endl;
  109. }
  110. if(Fail != 0)
  111. {
  112. cout<<"\tFail average :"<<(Failmark/Fail)<<endl;
  113. }
  114. starlines(); //call function starlines()
  115. cout << endl;
  116.  
  117. }
  118. //definition of the function starline.
  119. void starlines(void)
  120. {
  121. cout <<"\t*\a*\a*\a**************\a*\a*\a"<<endl;
  122.  
  123. cout <<endl;
  124. }
Last edited by Ancient Dragon; May 7th, 2008 at 12:56 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lerroy is offline Offline
2 posts
since Aug 2004
May 7th, 2008
0

Re: fUNTIONS

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

C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2.  
  3. #include<iomanip>
  4.  
  5. using namespace std; //program uses std;
  6.  
  7. double readInput(); //function prototype
  8.  
  9. void calculatetotals(double,double &,int &,double &,int &); //function prototype
  10.  
  11. void showresults(double,int,double,int); //function prototype
  12.  
  13. void starlines(void); //function prototype
  14.  
  15. int main()
  16. {
  17. double put=0;
  18.  
  19. double failmark=0; //fail mark
  20.  
  21. double passmark=0; //pass mark
  22.  
  23. int fail=0; //failing students
  24.  
  25. int pass=0; //passing students
  26.  
  27.  
  28. put=readInput();
  29.  
  30. while (put!=-999)
  31. {
  32. calculatetotals(put,passmark,pass,failmark,fail);
  33.  
  34. put=readInput();
  35. }
  36. showresults(passmark,pass,failmark,fail);
  37. return 0;
  38. }
  39.  
  40.  
  41. double readInput()
  42. {
  43. double mark;
  44.  
  45. cout<<"\nEnter student mark,-999 to stop : "; //prompt for student mark
  46.  
  47. cin>>mark; //reads mark
  48.  
  49. //the mark must not b = -999,musn't b -(<0) and musn't b >100(total mark).
  50.  
  51. while((mark!=-999 && mark<0)||mark>100)
  52. {
  53. cout<<"\nI think the test was out of 100..."<<endl; //if the user enters mark>50.
  54.  
  55. cout<<"\nStudent mark again please: "; //if wrong mark is entered
  56.  
  57. cin>>mark; //reads mark
  58. }
  59. return mark;
  60. }
  61.  
  62.  
  63. void calculatetotals(double mark,double &passmark,int &pass,double &failmark,int &fail)
  64.  
  65. {
  66. if(mark>=0 && mark<50) // for students who failed(got below 50)
  67. {
  68. fail++; //failed students.
  69. failmark+=mark; //fail mark.
  70. }
  71. if(mark>=50 && mark<=100) //for students who passed(got 50 and above ).
  72. {
  73. pass++; //passed students.
  74. passmark+=mark; //pass mark.
  75. }
  76. }
  77.  
  78.  
  79. void showresults(double Passmark,int Pass,double Failmark,int Fail)
  80. {
  81. cout<<fixed<<setprecision(2); //formatting the data type
  82.  
  83. cout<<endl;
  84.  
  85. cout<<"No. of students in a class : "<<Pass+Fail<<endl; //students in class
  86.  
  87. cout<<"\n\t\tResults :"<<endl;
  88.  
  89. starlines(); //call function starlines()
  90.  
  91. if(Pass!=0) //if pass = 0,is not calculated(average).
  92. {
  93. cout<<"\tPassed students : "<< Pass <<endl;
  94. }
  95. if(Fail!=0) //if fail = 0,is not calculated(average).
  96. {
  97. cout<<"\tFailed students : "<< Fail <<endl;
  98. }
  99.  
  100. starlines(); //call function starlines()
  101.  
  102. cout<<"\n\t\tAverages :"<<endl;
  103.  
  104. starlines(); //call function starlines()
  105.  
  106. if(Pass != 0)
  107. {
  108. cout<<"\tPass average :"<<(Passmark/Pass)<<endl;
  109. }
  110. if(Fail != 0)
  111. {
  112. cout<<"\tFail average :"<<(Failmark/Fail)<<endl;
  113. }
  114. starlines(); //call function starlines()
  115. cout << endl;
  116.  
  117. }
  118. //definition of the function starline.
  119. void starlines(void)
  120. {
  121. cout <<"\t*\a*\a*\a**************\a*\a*\a"<<endl;
  122.  
  123. cout <<endl;
  124. }
Last edited by Ancient Dragon; May 7th, 2008 at 12:56 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
real_napster is offline Offline
1 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Visual C++ Transparency
Next Thread in C++ Forum Timeline: Windows Message loop





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC