Ask Experts Questions for FREE Help !
Ask
    idle_09's Avatar
    idle_09 Posts: 3, Reputation: 1
    New Member
     
    #1

    Jul 7, 2008, 02:48 PM
    File Reading and Writing
    Hi! Thanks for helping me. I need to write a program (in C++) that reads the file Employee.dat as input and then outputs to 4 different files which are Managers.dat, Marketing.dat, Developers.dat, and Testers.dat. Each of the output files contains the name of the employees of its category.

    The fle Employee.dat contains following data:

    Sue Leon 4
    Robert Wise 3
    Sam Woo 1
    Nathan White 3
    Suzan Head 2
    Henry Williams 4
    Christine Mint 1
    Kim Leeds 4
    Elton Sue 3
    Ken Latch 2

    I tried to write the program but I don't know what to put in "SWITCH" loop. Here is what I have so far.


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

    int main()
    {
    string line;
    ifstream in_stream;
    ofstream out_stream;

    in_stream.open("Employee.dat");
    if (in_stream.fail())
    {
    cout << "Input file failed to open.\n";
    exit(1);
    }

    ofstream("Managers.dat", ios::app),
    ("Marketing.dat", ios::app),
    ("Developers.dat", ios::app),
    ("Testers.dat", ios::app);
    if (out_stream.fail())
    {
    cout << "Output file failed to open.\n";
    exit(1);
    }

    string first_name, last_name;
    int departmnet;
    enum department { Managers = 1, Marketing = 2, Developers = 3, Testers = 4 };

    in_stream >> first_name >> last_name;
    while (!in_stream.eof())
    {
    in_stream >> first_name >> last_name;
    switch (department)//error C2059: syntax error : ')'
    {//error : missing ';' before '{'
    case 1://error: illegal case
    cout << first_name << last_name;
    break;

    case 2://error: illegal case
    cout << first_name << last_name;
    break;

    case 3://error: illegal case
    cout << first_name << last_name;
    break;

    case 4://error: illegal case
    cout << first_name << last_name;
    }
    }
    return 0;
    }

Check out some similar questions!

Problems with reading from file [ 2 Answers ]

I have 2 files, one reads characters 1 coloumn of 11 strings,and the other reads integers a 100 numbers long(was in a 10 by 10 table but it didn't seem to like that), and is supposed to print both out togeather in a table 11 by 11, but for some reason it only prints the top row which consists of...

File W-7 form without tax return and why to file as a resident alien? [ 1 Answers ]

I came to USA in August 2004 on F1 Visa. I graduated and change status to H1b visa from October 2007. Now, I got married and my hasband came to USA on January 2008 on H4 visa. I have my brothers whom I can claim as they have green card and not earning anything. I will have to wait till May 2008...

How to improve reading and writing [ 1 Answers ]

Dear Sir or Madam, I am a Chinese student who has great interest in English. I want to improve my writing which is very essential for my future study in American university.I tried several methods but I couldn't feel any progress. It seems like I stay at the same place where I started....

Reading and Writing [ 6 Answers ]

Should a child read first or write first?


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.