need very easy C++ help, very fast please (deadline tomorrow)

Hello,
a friend of mine asked me to make this program for his university, the thing is i only know c# and have no idea about c++, his deadline is tomorrow and he have no idea what to do. so i thought i can ask for help here !
write a program that takes N grades from keyboard (float) & N, & perform the following calculations:
-avg,max,min,sorting
-standard diviation & variation

this should use function for each task including input values and olp results.

thanks very much.

We're not going to do someone else's complete homework assignment for them. Someone can help or give hints, but the person whose homework it is needs to put forth their own effort :)
i totally get where are you coming from, but this person is very dear to me, and he had a very unfortunate circumstances that stopped him from studying for month, he never failed me once and i am not planning to fail him, if i have i will learn the language now if someone can point me into the right things i need to complete the assignment, and it's not a long assignment so i will really, really REALLY thankful if someone can help me, i can write it in quick basic and someone can translate it (i don't have c# ATM).

sorry, i totally understand that's it's really not a good move to be asking people to do a complete assignment, and i never seen my self in this position, but this time i really need help.
thanks.

can anybody atleast tell me how many lines it would take to code it ?
thanks !
Last edited on
Write it in the language that you already know(C#), and ill help you to port it to C++.

Thanks, i don't have c# installed right now so i did it with Qbasic.
input "enter number of variables";N
for i = 1 to n
input z if z > max then max = z
if z < min then min = z
avg = avg +z
next i
print max,min,avg
sorry but i didn't know what standard diviation & variation exactly means, and also the i had a problem doing the sorting.
thanks for your helpin, and please tell me how many lines it will be.
Do you have a C++ compiler?
i am compiling them using http://ideone.com .
but i can download a compiler if necessary !
This code does the min and max:

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
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using std::cout;
using std::cin;
using std::vector;
using std::endl;
using std::sort;



int main(){
    vector<double> notes;
    cout<<"Enter some notes and hit ctrl+D followed by an <enter> to stop: ";
    double input;
    while(cin >> input){
        notes.push_back(input);
    }
    
    cout<<endl<<"Entered notes: ";
    for(int i=0; i<notes.size(); ++i){
        cout<<notes[i]<<" ";
    }
    sort(notes.begin(), notes.end());
    
    cout<<endl<<"Min: "<<notes[0]<<" Max: "<<notes[notes.size()-1];
    
    
  

}


Do some research on the other topics and implement it on top of the above code(ie how to calculate the standart deviation)
You'll need to know how to calculate those things on paper before you can code it.
The above code will not work on ideone as it waits for an CTRL+D to stop receiving notes.
Last edited on
Here it is working on ideone:

http://ideone.com/wIYcup
thanks alot for your help, i just downloaded Blocks so i now have a compiler, and i ran your program and it's running great (thanks again),
how can i replace the ctrl + d with an input to determined how many inputs gonna be (loop), and how can i put the avg and sorting in there please ?
thanks !
My code already sorted the notes:
sort(notes.begin(), notes.end());

You'll need to sum all the itens and divide by the total number of itens to get the avg... pretty simple.

1
2
3
4
5
6
7
8
    double sum, avg = 0;
    for(int i=0; i<notes.size(); ++i){
        
        sum +=notes[i];
    }
    avg = sum/notes.size();

    cout<<"\nThe avg is: "<<avg;

Put it just before the last '}'
Last edited on
thanks, but when executing the program after adding the code i am getting wrong avg.
i got -2032 for 5 small numbers !
Check it to see if you copied it right.

Here it is: http://ideone.com/WrrfWo
Last edited on
weird....
i copied the SAME code to my block compiler and still getting wrong results :/
i think i'll go back to the online compiler !
sorry if i'm being spoon fed, but i am trying to put the sorting in-there (from min to max) and getting rid of the ctrl + D and replacing it with input:
example in QBasic

input n
for i = 1 to n
'do things
next i

how can i translate it to C++ and add the sort, i only need those and i am done.

thanks alot, and i am VERY sorry for taking so much of your time !

EDIT :
i found this code for sorting , can't get it in there without messing up everything.
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
int partition(apvector <int> &array, int top, int bottom)
{
     int x = array[top];
     int i = top - 1;
     int j = bottom + 1;
     int temp;
     do
     {
           do      
           {
                  j - -;
           }while (x >array[j]);

          do  
         {
                 i++;
          } while (x <array[i]);

          if (i < j)
         { 
                 temp = array[i];    
                 array[i] = array[j];
                 array[j] = temp;
         }
     }while (i < j);     
     return j;           // returns middle subscript  
}
Last edited on
Here it is:

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
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using std::cout;
using std::cin;
using std::vector;
using std::endl;
using std::sort;



int main(){
    vector<double> notes;
    int howmany;
    double input;
    cout<<"\nHow many notes will you type: ";
    cin>>howmany;
    
    cout<<"\nNotes(hit enter after each note): \n";
    
    for(int i=0; i<howmany; ++i){
        cin >> input;
        notes.push_back(input);
    }
    
    cout<<endl<<"Entered notes: ";
    for(int i=0; i<notes.size(); ++i){
        cout<<notes[i]<<" ";
    }
    sort(notes.begin(), notes.end());
    
    cout<<endl<<"Min: "<<notes[0]<<" Max: "<<notes[notes.size()-1];
    
    double sum, avg, itens = 0;
    for(int i=0; i<notes.size(); ++i){
        
        sum +=notes[i];
    }
    avg = sum/notes.size();

    cout<<"\nThe avg is: "<<avg;
    cout<<"\nSorted notes: ";
    for(int i=0; i<notes.size(); ++i){
        cout<<notes[i]<<" ";
    }
            
    
    
  

}



You own me a beer :)
Last edited on
Believe me i owe you more than just a beer :D.
thanks alot, it even worked fine in blocks compiler !
thanks again !
No problem. You should read "Programming Principles and Practice Using C++ by Bjarne Stroustrup", its a great book on C++.

Bye.
Last edited on
Topic archived. No new replies allowed.