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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

int main()
{
    using namespace std;

    vector<int> 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 <range is 0 to 100> (Enter -1 to exit)" << endl;
		cin >> input;
		if (input != -1 and (input < 0 or input > 100))
			cout << "Please enter a valid grade <range is 0 to 100>" << 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 :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
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 (min<a[i])
        {
            min=a[i];
        }
    return min;
    }
}
int main ()
{
    int max=grades[0];
   for (i;i<=100;i++)
   {
       if (grades[i]>max)
       {
         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<char, std::char_traits<cha...
|33|error: 'minimum' was not declared in this scope|
|35|error: expected ';' before 'return'|
||=== Build finished: 4 errors, 2 warnings ===| */

what these statments in line 6 and 7 , what they represent ?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* part 2 of my program ,
 this program reads the grades and specify the number of 
grades , average , number of passing ,
failing grades .*/


#include <iostream>
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

double CalcMedian(vector<double> scores);

int main()
{
    vector<double> grades;
    double grade;
    double median;

    while (cin >> grade)
    {
        grades.push_back(grade);
    }

    median = CalcMedian(grades);

    cout << median << endl;
}

double CalcMedian(vector<double> scores)
{
  double median;
  vector<double>::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