Sign-in / Sign-up
Your question

C programming solver

Tags:
  • Programming
  • Switch
  • Apps
Last response: in Apps General Discussion
November 17, 2012 2:46:39 AM

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.

More about : programming solver

a b L Programming
November 17, 2012 3:39:42 AM

You are definitely new here; we will not do your homework for you ;) 

However, if you give it a good try and have a problem you may post a code sample and we will help then.
m
0
l
a b L Programming
November 17, 2012 9:27:58 AM

What do you not understand specifically?
m
0
l
Related resources
Can't find your answer ? Ask !
November 18, 2012 1:59:40 AM

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;

}
m
0
l
a b L Programming
November 18, 2012 9:01:09 AM

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.
m
0
l
November 18, 2012 8:28:47 PM

Ijack said:
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.


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.
m
0
l
a b L Programming
November 19, 2012 2:52:52 AM

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.
m
0
l
a b L Programming
November 19, 2012 8:22:48 PM

randomizer said:
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.

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. . .
m
0
l