0

I am trying to get the data from this file and add it to my constructor. I am doing something wrong, I understand, but I need the correction. Specifically, in my get grade function how do I set the class objects to the data within the file:

The file data is:

Mary Smith 10  5  8  10  6  2  10
Ken Lewis 5  3  2  10  8  9  10

My code:

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

void get_grade();
//void compute_grade();


class Student
{
  public :

  string firstname;
  string lastname;
  int lab1;
  int lab2;
  int lab3;
  int lab4;
  int lab5;
  int lab6;
  int lab7;

  Student(string a, string b, int c, int d, int e, int f, int g, int h){
    firstname = a;
    lastname = b;
    lab1 = c;
    lab2 = d;
    lab3 = e;
    lab4 = f;
    lab5 = g;
    lab7 = h;

  }

};

int main()
{

  get_grade();

}

void get_grade()
{


//Student stud2();

ifstream myfile; 
myfile.open("infile.txt");
myfile >> stud1.firstname; 

cout << stud1.firstname;


}

R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • It seems to me that you haven't quite grasped how to create and use instances of classes. Please take some time to understand these basics from a [good textbook](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). It's hard to guide you from your posted code when you haven't learnt how to use those basic concepts. – R Sahu Nov 17 '19 at 03:52
  • There are so many student with labs and grades questions in SO. Couldn't you find any of them? Please, try [google "site:stackoverflow.com c++ student"](https://www.google.com/search?q=site%3Astackoverflow.com+c%2B%2B+student). – Scheff's Cat Nov 17 '19 at 07:01

0 Answers0