Ok everything is good...I read in all my grades into each of the different arrays that they need to go in. Now Im trying to write a function that takes the grades and computes the average on a hundred point scale...for example:
Student 1
7 quiz scores 9 9.33 8 10 5.5 8 10 ==> the 5.5 score should be dropped, returned value: 90.55
6 project scores 20 47.5 47 45 47.5 48 ==> returned value: 94.44
2 exam scores 83 87 ==> returned value: 85.00
14 lab scores 100 98 96 100 98 92 88 96 92 86 92 94 100 96 ==> returned value 94.86
heres what I got: -
#include <cstdlib>
-
#include <iostream>
-
#include <string>
-
#include <vector>
-
#include <fstream>
-
using namespace std;
-
-
//Structure for holding all the grades
-
struct MyGrades
-
{
-
string student;
-
float quizzes[7];
-
float projects[6];
-
float exams[2];
-
float labs[14];
-
};
-
-
const int tot_quiz = 7;
-
const int tot_proj = 6;
-
const int tot_exam = 2;
-
const int tot_labs = 14;
-
const int tot_quiz_pts = 70;
-
const int tot_proj_pts = 300;
-
const int tot_exam_pts = 200;
-
const int tot_lab_pts = 150;
-
-
double ret_avg(float scores, int num_scores, int tot_pts);
-
-
int main()
-
{
-
// outputting the correct format for all the averages to go
-
cout << "No. -Name-- --Quiz-- -Project- -Exam- -Lab- -Total- Grade"
-
<< endl;
-
cout << "--- ----------- -------- ---------- ------ ----- ------- -----"
-
<< endl;
-
cout << endl;
-
-
int student_number = 1; //counter for number of students
-
-
ifstream in_file;
-
-
MyGrades Grades; //declare an instance of a Grades struct
-
in_file.open("grades.txt"); //opening the grades.txt file
-
-
if(in_file.fail()) //if function to make sure the file opened
-
{
-
cout << "Input file failed to open.\n";
-
exit(1);
-
}
-
-
while (in_file >> Grades.student) // reads in a string into a variable
-
{
-
//reads in all the grades into each seperate array
-
in_file >> Grades.quizzes[0] >> Grades.quizzes[1] >>
-
Grades.quizzes[2] >> Grades.quizzes[3] >> Grades.quizzes[4] >>
-
Grades.quizzes[5] >> Grades.quizzes[6] >> Grades.projects[0] >>
-
Grades.projects[1] >> Grades.projects[2] >> Grades.projects[3] >>
-
Grades.projects[4] >> Grades.projects[5] >> Grades.exams[0] >>
-
Grades.exams[1] >> Grades.labs[0] >> Grades.labs[1] >>
-
Grades.labs[2] >> Grades.labs[3] >> Grades.labs[4] >>
-
Grades.labs[5] >> Grades.labs[6] >> Grades.labs[7] >>
-
Grades.labs[8] >> Grades.labs[9] >> Grades.labs[10] >>
-
Grades.labs[11] >> Grades.labs[12] >> Grades.labs[13];
-
-
cout << " " << student_number << ". " << Grades.student << " "<<\
-
ret_avg(Grades.quizzes, tot_quiz, tot_quiz_pts) << endl;
-
-
-
-
student_number++;
-
}
-
-
}
-
-
double ret_avg(float* scores, int num_scores, int tot_pts)
-
{
-
double sum = 0;
-
double avg = 0;
-
for (int i = 0; i < num_scores; i++)
-
{
-
scores[i] += sum;
-
}
-
avg = sum / tot_pts;
-
return (avg * 100);
-
}
-
heres the error message i get when i run it:
In function `int main()':
grader.cpp:71: error: cannot convert `float*' to `float' for argument `1' to `double ret_avg(float, int, int)'
and heres the output when run without calling the function in the cout -
No. -Name-- --Quiz-- -Project- -Exam- -Lab- -Total- Grade
-
--- ----------- -------- ---------- ------ ----- ------- -----
-
-
1. Smith
-
2. Jones
-
I just want to know what's wrong with this function becuse I thought it would work perfectly but I guess I got something wrong in their. Also if anyone has any suggestions on how Im going to write a function to drop the lowest quiz from the quiz array and then run it in my ret_avg array to get the average of it on a scale of 100. Any help will be great!!!
10 2331
Okay I just tried something else but its outputting a zero when i call it and print it out...i get a 0 under --Quiz--
here it is:...i donno which is closer...my 1st func or this one. -
while (in_file >> Grades.student) // reads in a string into a variable
-
{
-
//reads in all the grades into each seperate array
-
in_file >> Grades.quizzes[0] >> Grades.quizzes[1] >>
-
Grades.quizzes[2] >> Grades.quizzes[3] >> Grades.quizzes[4] >>
-
Grades.quizzes[5] >> Grades.quizzes[6] >> Grades.projects[0] >>
-
Grades.projects[1] >> Grades.projects[2] >> Grades.projects[3] >>
-
Grades.projects[4] >> Grades.projects[5] >> Grades.exams[0] >>
-
Grades.exams[1] >> Grades.labs[0] >> Grades.labs[1] >>
-
Grades.labs[2] >> Grades.labs[3] >> Grades.labs[4] >>
-
Grades.labs[5] >> Grades.labs[6] >> Grades.labs[7] >>
-
Grades.labs[8] >> Grades.labs[9] >> Grades.labs[10] >>
-
Grades.labs[11] >> Grades.labs[12] >> Grades.labs[13];
-
-
ret_avg(Grades, tot_quiz, tot_quiz_pts, average);
-
cout << " " << student_number << ". " << Grades.student << " "<<\
-
average << endl;
-
-
-
-
student_number++;
-
}
-
-
}
-
-
double ret_avg(MyGrades& data, int num_scores, int tot_pts, double avg)
-
{
-
double sum = 0;
-
avg = 0;
-
for (int i = 0; i < num_scores; i++)
-
{
-
data.quizzes[i] += sum;
-
}
-
avg = sum / tot_pts;
-
return (avg * 100);
-
}
-
Your function prototype says: -
double ret_avg(float scores, int num_scores, int tot_pts);
-
but you function says: -
double ret_avg(float* scores, int num_scores, int tot_pts)
-
etc...
-
Fix your prototype.
ya disregard that part....i have it fixed in my program...I was just tryin stuff and I must of accidentally posted that version. something else is wrong with it.
heres what i currently have in my code: the function is just printing out a 0 for the quizzes for both students. -
const int tot_quiz = 7;
-
const int tot_proj = 6;
-
const int tot_exam = 2;
-
const int tot_labs = 14;
-
const int tot_quiz_pts = 70;
-
const int tot_proj_pts = 300;
-
const int tot_exam_pts = 200;
-
const int tot_lab_pts = 150;
-
-
double ret_avg(float scores[], int num_scores, int tot_pts, double avg);
-
-
int main()
-
{
-
// outputting the correct format for all the averages to go
-
cout << "No. -Name-- --Quiz-- -Project- -Exam- -Lab- -Total- Grade"
-
<< endl;
-
cout << "--- ----------- -------- ---------- ------ ----- ------- -----"
-
<< endl;
-
cout << endl;
-
-
double average = 0;
-
int student_number = 1; //counter for number of students
-
-
float exams[2];
-
float labs[14];
-
};
-
-
const int tot_quiz = 7;
-
const int tot_proj = 6;
-
const int tot_exam = 2;
-
const int tot_labs = 14;
-
const int tot_quiz_pts = 70;
-
const int tot_proj_pts = 300;
-
const int tot_exam_pts = 200;
-
const int tot_lab_pts = 150;
-
-
double ret_avg(float scores[], int num_scores, int tot_pts, double avg);
-
-
int main()
-
{
-
// outputting the correct format for all the averages to go
-
cout << "No. -Name-- --Quiz-- -Project- -Exam- -Lab- -Total- Grade"
-
<< endl;
-
cout << "--- ----------- -------- ---------- ------ ----- ------- -----"
-
<< endl;
-
cout << endl;
-
-
double average = 0;
-
int student_number = 1; //counter for number of students
-
-
-
ifstream in_file;
-
-
MyGrades Grades; //declare an instance of a Grades struct
-
in_file.open("grades.txt"); //opening the grades.txt file
-
-
if(in_file.fail()) //if function to make sure the file opened
-
{
-
cout << "Input file failed to open.\n";
-
exit(1);
-
}
-
-
while (in_file >> Grades.student) // reads in a string into a variable
-
{
-
//reads in all the grades into each seperate array
-
in_file >> Grades.quizzes[0] >> Grades.quizzes[1] >>
-
Grades.quizzes[2] >> Grades.quizzes[3] >> Grades.quizzes[4] >>
-
Grades.quizzes[5] >> Grades.quizzes[6] >> Grades.projects[0] >>
-
Grades.projects[1] >> Grades.projects[2] >> Grades.projects[3] >>
-
Grades.projects[4] >> Grades.projects[5] >> Grades.exams[0] >>
-
Grades.exams[1] >> Grades.labs[0] >> Grades.labs[1] >>
-
Grades.labs[2] >> Grades.labs[3] >> Grades.labs[4] >>
-
Grades.labs[5] >> Grades.labs[6] >> Grades.labs[7] >>
-
Grades.labs[8] >> Grades.labs[9] >> Grades.labs[10] >>
-
Grades.labs[11] >> Grades.labs[12] >> Grades.labs[13];
-
-
ret_avg(Grades.quizzes, tot_quiz, tot_quiz_pts, average);
-
cout << " " << student_number << ". " << Grades.student << " "<<\
-
average << endl;
-
-
-
-
student_number++;
-
}
-
-
}
-
-
double ret_avg(float scores[], int num_scores, int tot_pts, double avg)
-
{
-
double sum = 0;
-
avg = 0;
-
for (int i = 0; i < num_scores; i++)
-
{
-
scores[i] += sum;
-
}
-
avg = sum / tot_pts;
-
return (avg * 100);
-
}
-
ok i got it to work with : -
double ret_avg(float scores[], int num_scores, int tot_pts)
-
{
-
double sum = 0;
-
double avg = 0;
-
avg = 0;
-
for (int i = 0; i < num_scores; i++)
-
{
-
sum = scores[i] + sum;
-
}
-
avg = sum / tot_pts;
-
avg = avg * 100;
-
return (avg);
-
}
-
but my output is 85.4714 for the first student and
75 for the second.....how do i get it to be 85.47 and 75.00 i tried using all floats and all doubles in the function. any suggestions?
but my output is 85.4714 for the first student and
75 for the second.....how do i get it to be 85.47 and 75.00 i tried using all floats and all doubles in the function. any suggestions?
Use a manipulator. Check out setprecision, setfill and width member functions of cout.
any ideas on how i can drop one of those quizzes or even just make the lowest score in the array a zero would work for me. any suggestions?
Just loop though the array comparing each element to a test minimum. Start wioth 0 and compare array[0] to array[i]. If array[i] is less than array[0], then i is your new minimum. When you get to the end of the array, you can use the i to set array[i] to any value you want.
For a truly variable array, you need to use a vector.
Just loop though the array comparing each element to a test minimum. Start wioth 0 and compare array[0] to array[i]. If array[i] is less than array[0], then i is your new minimum. When you get to the end of the array, you can use the i to set array[i] to any value you want.
For a truly variable array, you need to use a vector.
okey dokey
thanks again!!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Colin Steadman |
last post by:
I have created a function to kill all session variables
that aren't in a safe list. This is the function -
Sub PurgeSessionVariables
For Each Item In Session.Contents
Select Case Trim(Item)...
|
by: Rasmus Grøndahl Olsen |
last post by:
I have tried to write a wait function but it seems like it will not brake
the while loop. I tried two different solutions.
Can anyone tell me what I am doing wrong, and come with another...
|
by: Matthew Wilson |
last post by:
I need to write a function crc(msg, len) that gets a char array of
length len and then calculates the crc32 for the code. I don't
understand what's going wrong in the code I have. It goes...
|
by: thesushant |
last post by:
hi,
whats the use of third argument to main( ), i.e. environmental
parameters.... if i am not wrong ? 1st 1 is argc 2nd is argv and what
bout the 3rd 1???????????
sushant
|
by: kernel.lover |
last post by:
hello,
I want to know if a fuction say malloc is declared as void *malloc()
then whats the significance of void here.
Does void * is used when function has the flexibility to return any
type of...
|
by: Mike Barnard |
last post by:
It's a simple test... VERY SIMPLE. But...
In an external stlyesheet some attributes don't show. With the same
styles cut and pasted to the test internally it works as expected.
Anyone tell...
|
by: Nosferatum |
last post by:
This script is meant to limit access by sessions, using username and
password from mysql db and redirect users after login according to a
given value belonging to each user in the db (10,20,30,40)....
|
by: muddasirmunir |
last post by:
i want to stop and play server server 2000 using vb6.
for this i got one function on internet which is
Option Explicit
Public Enum ServiceState
et_Stop
et_Pause
et_Start
End Enum
|
by: hiqu |
last post by:
This issue is driving me nuts and not able to figure out whats wrong.
I've this code in my firefox extension. Firefox always hangs and
reports the script is busy.
if I introduce a break...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |