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 2368
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.
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)
Case "Authenticated"
Case "CI_CODE"
Case "organisation_description"
Case "location_description"
|
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 suggestion?
If I call the function like this: wait(500); it should wait 500ms right?
function wait(time) {
while(1){
setTimeout("break;",time);
}
}
|
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 bit-by-bit,
XORing the most significant bit of the FCS with the msb of the
character.
All comments are welcome. Yes, this is for a school assignment. If I
wanted to just grab some googled code I would; I want to actually
understand what I am doing...
|
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 value by casting that functions with appropriate data type?
| |
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 me why? Its probably sooooooo obvious, but it is 1.19 am!
Thanks.
www.thunderin.co.uk/
|
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).
(the included config is just server settings, the login is just a
login form).
The script appear to connect but will not redirect users, it seems
that even with correct login details, it won't validate.
|
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 statement in the for(;;) loop below, then
no issue.
Any help would be appreciated!
function getStuff()
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |