this is a c++ program. ok. so this is my problem where i am supposed to get data from one file, read it in and make the proper adjustments to it, and output it on to another file. i'm supposed to use structs. the input file has this data:
348 Jack BLaCK
98 mITchel MiCK
456 JohN doE
etc...up to a 15 different names
the first number is their ID number and their first and last names, respectively. i am supposed to write a program so that the output will be called up from another file looking like this...
Students ID
Black, Jack 348
Doe, John 456
Mick, Mitchel 98
this is what i have so far but i dont know if i have an infinite loop somewhere since it wont stop after i compile and output it. and i'm wondering if i am lableing all my variables correctly. i dont know when to label them as struct or string.
#include <iostream>
#include <fstream>
#include <cstring>
#include <cctype>
#include <iomanip>
using namespace std;
struct file1
{
int id;
string fname;
string lname;
};
void fixstring (string&);
void get_data (file1 [], int&);
const int MAX = 30;
int main ()
{
string filename1;
string/struct studentnames;
string filename2;
string/struct output;
int n = 0;
ifstream inf;
ofstream outf;
cout << "enter file name" << endl;
cin >> filename1;
cout << "enter output file name << endl;
cin >> filename2;
inf.open (filename1.c_str());//do i need this to open up my file for this? i'm confusing it when i had to do a string file on my last exam
file1 names[max];//i'm not so sure what i am tring to do here but i want it so that i associate the word "names" to work throughout my program or at least that what i want my structs to be tied to.
int n;
get_data (names, n);
//then i need it to ouput into another file so would i do this?
// outf.open (filename2.c_str());
// outf << left << setw (40) << "NAME" << "ID#" << endl;
// at this point, i'm not so sure how to return all my data that i have aleady manipulated.
return 0;
}
void fixstring (string& names)
{
int wlen = names.length();
names[0] = toupper (names[0]);
for (int i = 1; i < wlen; i++)
names [i] = tolower (names[i]);
}
void get_data (file1 names[], int& n)
{
n = 0;
cin >> names [n]. id;
while (!cin.eof())
{
cin >> names[n].lname >> names[n].fname;
fixstring (names[n].lname);
fixstring (names[n].fname);
n++;
cin >> names[n].id;
}
}
in my mind, i know what i want to do but syntatically, i am probably one of the worst programmers in the world when it comes to programming what i want it to do. any feedback and help in correcting this would be great.