-
Help PLease
I need to do this program for an example workshop but cant get my head around it:
Program details as follows:
Input to the program the exam number and computer arch and programming results for 10 people. Three arrays - ExamNo[10], Arch[10] and prog[10] are used to hold these items. The First name and surname of each student should also be entered, concatenated into one string and output to an array called wholename[10]
We need to check weather the exam numbers are valid. An exam number should consist of 7 digits only Include a function in your solution that will pass in the exam number, determine if the exam number is valid or not and return an appropriate message. only valid exam numbers should be stored in the array ExamNo
For each of the students, calulatE display the average mark for the class. For the Computer Arch results, find out how many students received below the class average. Find the name of the students with the highest result in each subject. These students' name are to be displayed and told that they will receive a special prize for their outstanding results.
For programming results, calulate and display standard deviation. I think this is the following steps in order to get it
1. Calculate the average of the programming results
2. Calculate the variance(d) by subtracting each result from the average
3. Square each of these results to get variance squared.
4. Sum all the variances squared
5. Divide by the number of numbers
6. Get the Square root of the result which is the standard Deviation.
Display the exam number, whole name and both results for all students.
Let me know what ya think.
-
Which parts of the assignment are you having trouble with?
-
No one is going to do your work for you. You need to present a specific part of the problem, and show some code that you have tried.
-
I don't think he was asking us to do his work. I think he was asking us if the steps he wrote down are a good method for doing this.
-
-
Oh but we can yell at them for not giving a good thread title ;)
-
I find your steps for calculating the std dev a bit hard to follow (just the Eglish reading of it), but it appears as if you have the right formula for it.
Your solution certainly sounds workable, though. If you know structures/classes, then this would be a good use of a data struct (the group relevant information so you only have one array).
-
Yeah, it seems like a good way to calculate the standard deviation, although if you are still unsure you can always 'google' for it.
Zach's suggestion of using classes and structs is a good way to go about solving your problem -although, you could probably do the same by using functions and arrays. Less jazzy but still workable.
Question, when you enter the name of the student, I assume you mean enter the first name as one string and the Surname as another and then concatenate the two, why not just use cin.getline?
Having said that, you may have not come across this quite yet. Which is probably why you're not using it.
Good luck though.
:confused:
-
Right this is what i have done so far any suggestions i am at a kinda standstill now where to go. any help would be very grateful
Code:
// Program to show use of arrays
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<ctype.h>
#include<string>
void input (void);
void calc (void);
void display (void);
void percent (void);
void vvv (void);
int checknumb(char[7]);
string fname ;
string lname;
const int z = 1;
string wholename[z];
int results[z], variance[z] ;
int tot,total;
char * examn[z];
int arch[1];
float ave,ave1;
float perc[10] ;
int main(void)
{
input();
percent();
calc();
display() ;
cout<<" Please type in any key to finish"<< endl;
getch();
return 0;
}
void input (void)
{
for (int i = 0; i<z; i++)
{
char studnumber[7];
bool OK = false;
while (!OK)
{
cout<<" Enter a student number"<<endl;
cin>>studnumber;
if (checknumb(studnumber))
{
cout<<"This number is valid" <<endl;
examn[i]=studnumber;
OK = true;
}
else
cout<<" Unfortunately this number is invalid"<<endl;
}
cout<<"Type in your first name "<<endl;
cin>>fname;
cout<<"Type in your last name "<<endl;
cin>>lname;
wholename[i]= fname+" "+lname;
cout<<" Please type in result for programming "
<<(i+1)<<endl;
cin>>results[i];
cout<<" Please type in result for architecture "<<(i+1)<<endl;
cin>>arch[i];
tot+= results[i];
total+=arch[i];
}// close for loop
} // close function
int checknumb(char code[])
{
// confirm string is right length
if(strlen(code)!= 7)
return 0;
//confirm string is all digits
for (int i = 0; i<7;i++)
{
if (!isdigit(code[i]))
return 0;
}
//return -1 if all is Ok
return -1 ;
} // end checknumb
void percent(void)
{
for (int i=0;i<6;i++)
{
perc[i]=results[i]/total*100;
cout<<setiosflags(ios::showpoint|ios::fixed)
<<setprecision(2)<<perc[i]<<endl<<endl;
}
}
void calc (void)
{
ave = tot/z;
ave1 =total/z;
for (int i = 0; i <z;i++)
{
variance[i] = results[i] - ave ;
}
}
void display (void)
{
// cout<<"First Name + Last Name "<<wholename[z]<<endl; */
cout<<"\n\nTotal of Programming "<<tot<<endl;
cout<<"\n\nTotal of Arch "<<total<<endl;
cout<<"\nAverage of results of Programming "<<setiosflags(ios::showpoint|ios::fixed)<<setprecision(2)<<ave<<endl;
cout<<"\nAverage of results Of Arch "<<setiosflags(ios::showpoint|ios::fixed)<<setprecision(2)<<ave1<<endl;
cout<< "\n\n Results " << setw(20)<<"Variance"<<endl;
for (int h = 0; h<z;h++)
{
cout<<results[h]<<setw(20)<<variance[h]<<endl;
}
}
//
Code:
// Program to show use of arrays
-
Your original post says write a program showing the
Quote:
results for 10 people
Obviously, this is your next plan of action.
-
Oh you've done that:
You should have set 'const int z =10' though.
Now write a function that counts how many students got below the class average. Then write a function that returns the name of the student with the highest score.
Code:
int largest=0;
for (int i=0; i<10; i++)
{
if(student[i]>largest)
{
largest=student[i];
}
}
or something
-
Well you could work on your indentation skills - that last post was a mess.
Or configure your text editor to only use spaces for indentation - mixing spaces and tabs really sucks on a message board. Spaces mean everyone sees what you see, not what your super-clever editor manages to tidy up for you.