can I pass
grades.projects in my function call that is
void get_scores(ifstream& infile, int num_scores, grades.projects)
and the function would look like
void get_scores(ifstream& infile, int num_scores, records& grades)
{
in_file >> grades.name;
for (int i = 0; i < num_scores; i++)
{
in_file >> records grades[i];
}
I was going to try something like this but Im not sure this would work. And I still have a couple errors I cant fix
-
-
#include <iostream>
-
#include <string>
-
#include <vector>
-
#include <fstream>
-
using namespace std;
-
-
ifstream in_file;
-
//structure that holds student record information.
-
struct records
-
{
-
string name;
-
float quizes[7];
-
float projects[6];
-
float exams[2];
-
float labs[14];
-
};
-
-
const int num_quizes = 7;
-
const int num_exams = 2;
-
const int num_projects = 6;
-
const int num_labs = 14;
-
-
-
const int quizes_pts = 70;
-
const int exams_pts = 200;
-
const int projects_pts = 300;
-
const int labs_pts = 150;
-
-
void get_scores(ifstream & infile, int num_scores, records& grades);
-
void get_avearage(records grades, int num_scores,int tot_pts,float& average,string);
-
-
int main()
-
{
-
// Ask the user for a file name
-
cout << "Enter a file name: ";
-
string file;
-
cin >> file;
-
cout << file;
-
-
int counter = 1;
-
-
-
records grades;
-
// Define a file input stream and open the file
-
in_file.open("file.txt"); //opening file
-
-
if (in_file.fail())
-
{
-
// Failed to open the file (file doesn't exist or isn't readable)
-
cout << "Could not open file: " << file << "\n";
-
exit(1);
-
}
-
-
-
float quiz_ave = 0.0;
-
float exam_ave = 0.0;
-
float project_ave = 0.0;
-
float lab_ave = 0.0;
-
-
// Repeatedly get characters from the file
-
-
-
void get_scores(ifstream& infile, int num_quiz, records& grades.quizes); //function for inputing info in struct.
-
-
void get_avearage(records grades.quizes, int num_quizes, int quizes_pts, float& quiz_ave, "quiz"); //function for average
-
-
-
-
-
-
// Close the file
-
in_file.close();
-
-
-
return 0;
-
}
-
-
//function that takes in parameters to input scores in array
-
void get_scores(ifstream& infile, int num_scores, records& grades)
-
{
-
in_file >> grades.name;
-
-
for (int i = 0; i < num_scores; i++)
-
{
-
in_file >> records grades[i];
-
-
}
-
-
}
-
-
//funtion that takes the average of the inputed scores
-
void get_avearage(records grades, int num_scores,int tot_pts,float& average,string name)
-
{
-
if (!("name" == "projects"))
-
{
-
float a;
-
for (int i = 0; i < num_scores; i++)
-
{
-
records grades[i] += a;
-
}
-
average = (a/tot_pts);
-
-
else
-
float b;
-
record grades[0] = b;
-
average = (b/20);
-
-
for (int i = 1; i < num_scores; i++)
-
{
-
float c;
-
records grades[i] += c;
-
}
-
ave_1 = (c/(tot_pts - 20));
-
average += ave_1;
-
}
-
}
-
-
-
}
main.cpp: In function `int main()':
main.cpp:63: error: expected `,' or `...' before '.' token
main.cpp:65: error: expected `,' or `...' before '.' token
main.cpp: In function `void get_scores(std::ifstream&, int, records&)':
main.cpp:85: error: expected primary-expression before "grades"
main.cpp:85: error: expected `;' before "grades"
main.cpp: In function `void get_avearage(records, int, int, float&, std::string)':
main.cpp:99: error: expected initializer before '+=' token
main.cpp:103: error: expected primary-expression before "else"
main.cpp:103: error: expected `;' before "else"
main.cpp:105: error: `record' was not declared in this scope
main.cpp:105: error: expected `;' before "grades"
main.cpp:106: error: `b' was not declared in this scope
main.cpp:111: error: expected initializer before '+=' token
can anyone help?