I am new to these forums and new to c++ but not new to programming; however, I have run into an issue with an assignment from one of my classes.
I have a c++ project (made in visual studio 2010) with 3 sources files that I'm using:
// grade.h
// version 1
const int maxsize=20;
struct Student
{
char stuID[5];
int midterm;
int final;
int quiz1;
int quiz2;
double average;
char grade;
};
class Stuclass
{
public:
//constructor
Stuclass();
// read data from a file
void input();
// output data to a file
void output();
private:
Student myclass[maxsize];
int numberofstudents;
// calculate the average grade and final
// letter grade for each student
void calculation();
};
// grade.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
void Stuclass::input()
{
ifstream in_stream;
in_stream.open("input.dat", ios::in);
if(in_stream.fail())
{
cerr<<"Intput file opening failed.\n";
cin.get();
exit(1);
}
int x;
// read number of students
in_stream >> x;
numberofstudents=x;
for (int i=0; i<numberofstudents; i++)
{
// read Student ID (4-digit)
in_stream >>myclass[i].stuID;
// read Quiz1
in_stream >>myclass[i].quiz1;
// read Quiz2
in_stream >>myclass[i].quiz2;
// read Midterm
in_stream >>myclass[i].midterm;
// read Final
in_stream >>myclass[i].final;
// calculate the average
myclass[i].average = (.25 * (myclass[i].quiz1 + myclass[i].quiz2)) +
(.25 * (myclass[i].midterm)) +
(.50 * (myclass[i].final));
// calculate the letter grade
if(myclass[i].average >= 90)
{
myclass[i].grade = 'A';
}
if(myclass[i].average >= 80 && myclass[i].average < 90)
{
myclass[i].grade = 'B';
}
if(myclass[i].average >= 70 && myclass[i].average < 80)
{
myclass[i].grade = 'C';
}
if(myclass[i].average >= 60 && myclass[i].average < 70)
{
myclass[i].grade = 'D';
}
if(myclass[i].average < 60)
{
myclass[i].grade = 'F';
}
}
in_stream.close();
}
void Stuclass::output()
{
ofstream out_stream("output.dat");
if(out_stream.fail())
{
cout<<"Output file opening failed.\n";
exit(1);
}
out_stream << "StuID\tQuiz1\tQuiz2\tMidterm\tFinal\tAverage\tFinal Grade\n";
for(int i = 0; i< numberofstudents; i++)
{
out_stream << myclass[i].stuID << "\t" <<
myclass[i].quiz1 << "\t" <<
myclass[i].quiz2 << "\t" <<
myclass[i].midterm << "\t" <<
myclass[i].final << "\t" <<
myclass[i].average << "\t" <<
myclass[i].grade << endl;
}
out_stream.close();
}
void Stuclass::calculation()
{
}
#include "stdafx.h"
#include <iostream>
using namespace std;
//int _tmain(int argc, _TCHAR* argv[])
int main()
{
Stuclass classroom();
cin.get();
classroom.input;
classroom.output;
return 0;
}
When building the source, I get 2 errors in int_tmain at classroom.input; and classroom.output; The errors both say "error C2228: left of '.input' must have class/struct/union." What I don't get is this: classroom is an Instance of my Stuclass class, so why would I get an error like this? If anyone could help me, or at least give me hints to help me learn why this happens, I would be very thankful. If possibly, provide an explanation so I know what I'm doing wrong. Thank you


Sign In
Create Account

Back to top









