assignment due at 12 i have done most of the work just a few errors

closed account (D9hk4iN6)
yes guys this is hw but really i have done most of the work but i just have not mastered it enough to solve this here is the question and the code i have. Please help me fix it its due in 2 and a half hours. Thank You.


Write a program that reads student information from a file (one student per line) in the format:
StudentFirstName StudentLastName StudentID StudentTest1 StudentTest2 StudentTest3
and outputs them in the following format:
StudentLastName, StudentFirstNameInitial StudentID StudentTest1 StudentTest2 StudentTest3
where StudentFirstNameInitial is the initial (first letter) of the first name of student. Let us assume that the name
(StudentLastName, StudentFirstNameInitial) can be at most 15 characters, the StudentID can be at most 7
characters, and the StudentTest scores need up to 7 characters. The StudentTest scores should be formatted to have
exactly 2 decimals and should be aligned to the right. The rest of the values should be aligned to the left. Make sure you
are not missing any of the digits of the student ID. File.txt is an example of input file that you can use to test your
program.


// part 4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


struct Student
{
string first, last;
int grade;
};
istream& operator>>(istream& in, Student &S);
ostream& operator<<(ostream& out, Student S);



int main()
{
// Get file name and open file
string fname;
cout << "Enter file name (file1.txt): ";
cin >> fname;
ifstream fin("file1.txt");

// read data from file
int n;
string junk;
fin >> n >> junk;
Student *S = new Student[n];
for(int i = 0; i < n && fin >> S[i]; ++i);

return 0;
}

istream& operator>>(istream& in, Student &S)
{
return in >> S.first >> S.last >> S.grade;
}

ostream& operator<<(ostream& out, Student S)
{
return out << S.first << ' ' << S.last << ' ' << S.grade;
}
closed account (Sy0XoG1T)
Why would you post the same topic twice?
closed account (D9hk4iN6)
you gotta help me out this is 2.5 points out of a hundred im pretty desperate right now lol

i have been trying to learn it and this is what i have so far please help


// part 4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


int main()
{
ifstream in ("file1.txt");
ofstream out;
out.open ("file2.txt",ios::out);

if ( in.bad() )
{
cout <<"Error: could not open the input file file1.txt\n";

}
string str;
while (getline (in, str))
out << str << "\n";

in.close();
out.close ();
cout << "Finished copying the file";
string a;
string b;
string c;

cin >> a;
cin >> b;
cin >> c;

cout << a;
cout << b;
cout << c;


// Get file name and open file

in >> a;
in >> b;
in >> c;

out <<a;
out <<b;
out <<c;


}
Last edited on
Topic archived. No new replies allowed.