C programming solver

Akanksha_27

Honorable
Nov 16, 2012
1
0
10,510
0
Write a program to find grace marks for a student using switch. The user should enter the class obtained by the student and number of subjects he has failed in.
• If student gets 1st class and the number of subjects he failed in is greater than 3, then he does not get any grace. If the number of subjects he failed is less than or equal to 3 then grace is of 5 marks per subject
• If the student gets second class and the number of subjects he failed in is greater than 2, then he does not get any grace. If the number of subjects he failed in is less than or equal to 2 then the grace is of 4 marks per subject.
• If the student gets third class and the number of subjects he failed in is greater than 1, then he does not get any grace. If the number of subjects he failed is equal to 1 then the grace is of 5 marks per subject.

 

hdeezie80

Honorable
Jul 18, 2012
14
0
10,560
0
I'm going to give you some code to start from, if you do not understand this than reply back and I will try to explain it in further detail, the selection structure is a very basic programming concept and also very important so if you don't get this your going to have a real hard time moving to oo programming.
The switch statement is basically a fancy if statement but im not going to go into detail on this subject, look up control structures for c/c++.

//your code should be something like this

int main()
{

int classNum; // class is a keyword so it can't be use to name a variable
int subjectsFailed;
int grace = 0;

cout << "Enter class: ";
cin >> class;

cout << "Enter subjects failed: ";
cin >> subjectsFailed;

switch (classNum) // variable to be tested is class
{
case 1: // same as if (classNum == 1)
if (subjectsFailed <= 3) // your next condition to test
grace = 5; // if true update grace variable
break; // stops further testing
case 2:
if (subjectsFailed <= 2)
grace = 4;
break;
case 3:
if (subjectsFailed == 1)
grace = 4;
break;
}

if (grace == 0) // if grace is at default value
cout << "Student does not recieve grace" << endl;
else // if grace is anything but 0
cout << "Student recieves grace of " << grace << "marks per subject."

return 0;

}
 

Ijack

Distinguished
I'm very disappointed to see an almost complete solution given here. It's not as if it was a difficult problem.

What help, in the long run, is it going to be to the OP to just copy what has been printed here? With any luck the tutors are smart enough to check sites like this and the guy will get no credit for cheating.
 

hdeezie80

Honorable
Jul 18, 2012
14
0
10,560
0


Ehhh... Yeah your right, definitely wasn't the most constructive way to explain the selection structure to him but really it's his responsibility to learn it in the long run, hopefully he reviews the code and tries to make since of it.
 

randomizer

Distinguished
Moderator
Jul 24, 2006
880
0
19,260
62
People who just post their programming questions online (this is literally just the question) aren't interested in learning or "the long run". They are interested in passing some assignment that they don't care about.
 

PhilFrisbie

Distinguished
Apr 22, 2006
666
0
19,310
53

Yep, and then when they graduate with their degree in Computer Science they will get hired by a software company and produce buggy code, which gives all programmers a bad reputation :(

I helped a woman years ago who wanted to integrate one of my free open source software projects into hers for her final MASTERS project. She had a BS in Computer Science, but she could did not even know where to begin to add a few C source files together using a makefile. . .
 
Thread starter Similar threads Forum Replies Date
aymen9309 Apps General Discussion 1
SyndiShanX Apps General Discussion 1
D Apps General Discussion 1
BlueMoon1890 Apps General Discussion 0
Neon The (Anthro) Umbreon Apps General Discussion 1
K Apps General Discussion 2
T Apps General Discussion 10
M Apps General Discussion 2
R Apps General Discussion 3
S Apps General Discussion 2
N Apps General Discussion 1
P Apps General Discussion 4
A Apps General Discussion 8
M Apps General Discussion 6
S Apps General Discussion 1
convaallaria Apps General Discussion 5
H Apps General Discussion 3
H Apps General Discussion 1
M Apps General Discussion 3
Bruceification73 Apps General Discussion 12

ASK THE COMMUNITY