### help me with code !

Pages: 12
hey , i got this homework i tried many times to solve with no result , can some 1 guide me with some instructions , we program in code blocks only , can i found some one here give me a hand with this plz ..

http://www.anisnazer.com/courses/fall_2012_2013/c/files/hw/homework3.pdf

this the dirct link to the homework .

w8 for responces
This is pretty straight forward and well laid out for you. Where are you having issues?
closed account (3qX21hU5)
I agree it is straight forward. And we cant really help you without knowing what you are having trouble with. Also remmber wheb you post code to these forums use the codetags feature (the <> off to the right when replying)
well, if you don't mind some C++11:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960`` ``````#include #include #include #include int main() { using namespace std; vector grades; bool flag = true; while(flag) { int temp; cout << "Enter a grade (-1 to end): "; cin >> temp; if (temp == -1) flag = false; else if ( (temp < 0) || (temp > 100) ) cout << "Error! Grade must be between (0 and 100)" << endl; else grades.push_back(temp); } cout << "--------------------" << endl; sort(grades.begin(), grades.end()); double average = 0.0; int passing, failing = 0, num = grades.size(); for(auto v: grades) { average += v; if (v < 50) ++failing; } average /= num; passing = num - failing; double median; if (num % 2) median = grades.at((num+1) / 2); else median = ( grades.at(num/2) + grades.at((num/2)+1) ) / 2.0; double deviation = 0.0; for(auto v: grades) deviation += (v - average)*(v - average); deviation *= 1.0 / (num - 1); deviation = sqrt(deviation); cout << "Number of students = " << num << endl; cout << "Average = " << average << endl; cout << "Maximum grade = " << grades.back() << endl; cout << "Minimum grade = " << grades.front() << endl; cout << "Median = " << median << endl; cout << "Syandart deviation = " << deviation << endl; cout << passing << " student(s) passed" << endl; cout << failing << " student(s) failed" << endl; return 0; }``````
ok
Last edited on
closed account (3qX21hU5)
Rewrite it yourself? Don't expect other people to do your work for you. He actually answered your question for you and you dont "have the time" to correct a few errors? Your not going to learn by copy and pasting you know.

We see posts here everyday saying they have 5 finals and even more homework so they don't have time but maybe if they started on the assignments before the last minute they would have time to do it ;p. Professors don't give out a final and say "hey you got 2 days to get it done now do it".
Last edited on
i said before i still noob and i dont have the time now after i finish my final exams the day after tommorw i will learn this languge its not my specailst , but i like it .

This is not a homework answer site. If someone essentially gave you the answer and you still can't figure out a few errors, then I really doubt you've been doing the work before now either. Good Luck.
Here is 90% of the code you need. All you need now is to solve the Math problem.

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````const int studentLimit = 5; int main () { int input = 0; int studentCount = 0; int minGrade = INT_MAX; int maxGrade = INT_MIN; double grades[studentLimit]; do { cout << "Enter a valid grade (Enter -1 to exit)" << endl; cin >> input; if (input != -1 and (input < 0 or input > 100)) cout << "Please enter a valid grade " << endl; else if (studentCount > studentLimit) cout << "Student limit reached..."; else { grades[studentCount] = input; if (input < minGrade and input >= 0) minGrade = input; if (input > maxGrade and input <= 100) maxGrade = input; studentCount++; } } while (input != -1 and studentCount < studentLimit); // you can exit here if you want if (input == -1) { cout << "Exiting Program..."; } ``````
Last edited on
My code works perfectly. You just need to enable C++11 in your compiler. Google how to do it. I hope, you could do at least this.
thank you all for this advices now iam trying step by step to write this program i start with the minimum and maximum grade i write this code , any advices :
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include using namespace std; int i=1; double grades[100]={}; double minimun(double a[],int 100) { double min=a[0]; for (i;i<=100;i++) { if (minmax) { cout <<"the maximum grade=" << max=grades[i]; } } cout << "the minimum grade=" << minimum(grades,100) return 0; } /*|7|error: expected ',' or '...' before numeric constant| |In function 'double minimun(double*, int)':| |12|warning: statement has no effect| |In function 'int main()':| |25|warning: statement has no effect ||29|error: no match for 'operator=' in '((std::basic_ostream

what these statments in line 6 and 7 , what they represent ?
Last edited on
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354`` ``````/* part 2 of my program , this program reads the grades and specify the number of grades , average , number of passing , failing grades .*/ #include using namespace std; int main () { double input; double grades; int i; int sum=0 ,pass=0 , fail=0; for (i=0;i<100;i++) { cout << "Enter the grade please(-1 to end)=" ; cin >> input; if (input >=0 && input <=100 && input !=-1) { sum=sum+input; grades++; if (input >=50) { pass++; } else { fail++; } } else if (input == -1) { cout << "The average of the grades=" << sum/grades ; cout << "\nThe number of grades u enterd=" << grades ; cout <<"\nThe number of passing grades=" << pass ; cout << "\nThe number of failing grades=" << fail ; break ; } else { cout << "error, grade must be between (0 and 100)\n" ; } } return 0; }``````

its look like good code i compile and run it with no errors or warning , any advices , is this good code for such full program ?
Last edited on
closed account (3qX21hU5)
See I find it completely stupid that professors would "not allow" students to use C++11. Shows that a lot of professors are stuck in the old ways and are holding back students because of it.

Also the program looks good for what you have but your missing some things like the median of the grades, the average grade, use arrays and some other things. Also you your first part has some mistakes also. But this is a very good start always start with what you know you can do then add the stuff that you are having trouble with step by step. Make little changes and then make sure they compile.

Also what IDE and Compiler are you using? If you are using the old bloodshed Dev C++ I would recommend upgrading to either the new orwell Dev C++ (I think thats the name) or code::blocks or Visual Studio Express
zereo,i wish he was a professor , or a doctor he shorten the material(c++ programing) thats why i have difficulties .
now all i need little support in:
1-how sorting grades in array and use it in function and call an array function.
2-how to find the median .
 how to find the median

http://www.mathsisfun.com/median.html
Sort the values.
If there are an odd number of values, pick the middle one.
If there are an even number of values, pick the middle two, and take their average.
closed account (3qX21hU5)
For sorting usually people start with bubblesort you can search the forums and there should be plenty of examples with arrays.
chervil ty for ur support , but i alrdy know if odd the middle number , and if ever its the sum of the both middle numbers , but how can i specify this mid number , because the use will enter the number of grades ?
 how can i specify this mid number , because the use will enter the number of grades ?

Take the the number of grades entered by the user and divide by two.
closed account (3qX21hU5)
Here is a quick example of how to find the median. I removed some of the code so I don't just give you the answer but it should help you with a general idea of how to do it.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` ``````#include #include #include using namespace std; double CalcMedian(vector scores); int main() { vector grades; double grade; double median; while (cin >> grade) { grades.push_back(grade); } median = CalcMedian(grades); cout << median << endl; } double CalcMedian(vector scores) { double median; vector::size_type size = scores.size(); // Removed so you can figure it out. (HINT: You need to sort the vector or other container) if (size % 2 == 0) { // Removed so you can figure it out } else { // removed so you can figure it out } return median; }``````
Last edited on
That is great idea for..nyc .
Pages: 12