Having difficulty creating and using classes.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #16
    Originally posted by samimmu
    i wish u can get my wants or requirement, actually here i can not create a file and cin the information for each students, i want the size to 100, but unfortunately i can not use the for loop

    #include<iostre am>
    #include<fstrea m>
    #include<string >
    #include<iomani p>
    using namespace std;

    const int size=10;
    int main()
    {

    ifstream inFile;
    ofstream outFile;

    int quiz1, quiz2, quiz3, quiz4, quiz5;
    double average;
    char studentId;
    inFile.open("a: \\quiz.txt");
    outFile.open("a :\\quizavg.out" );


    // for(int i=0 ; i< size; i++)
    cout<<" the students information"<<e ndl;
    inFile>>student Id;
    outFile<<" student ID: "<< studentId<< endl;
    inFile>> quiz1>>quiz2>> quiz3>> quiz4>> quiz5;
    outFile<<" Quize scores:"<< setw(4)<< quiz1
    << setw(4)<< quiz2<< setw(4)<< quiz3<< setw(4)<< quiz4
    <<setw(4)<<quiz 5<< endl;

    average= static_cast<dou ble>(quiz1+quiz 2+quiz3+quiz4+q uiz5)/5.0;
    outFile<< " Average test score:"<< setw(6)<< average<< endl;


    inFile.close();
    outFile.close() ;
    system("pause") ;
    return 0;
    }
    The A:\ drive is usually recognized as 'floppy disk,' are you trying to write to a floppy, or your hard drive? It's possible that the letter was assigned to a local drive, but I'd check that out. (C is usually the hard disk)

    If you can't use a for loop, why not use one of the other loops to mimick a for loop? Such as while counter < 100 do stuff, and increment counter. Or if counter < 100, dostuff, increment counter.

    At first glance, your files look like they're declared properly (unless there's no floppy in there...).

    Comment

    Working...