1 /* Roy Keene 2 CS 2314 3 Section 04 4 Lab 02 5 27 Aug 02 6 lab2.cc 7 8 Fully tested configurations: 9 MSVC++ 6.0 i386 Windows XP 10 Sun Workshop 6.0 sun4u Solaris 11 pgCC 4.0-2 i386 Linux 12 g++ 3.0.3 sun4u Solaris 13 g++ 3.0.2 ip27 IRIX 14 g++ 2.95.4 i386 FreeBSD 15 g++ 2.95.4 alpha Linux 16 g++ 2.95.4 powerpc Linux 17 g++ 2.95.4 sparc64 Linux 18 g++ 2.95.4 sparc32 Linux 19 g++ 2.95.3 i386 Linux 20 c++ 2.95.2 powerpc MacOS X Darwin 21 g++ 2.8.1 sun4u Solaris 22 23 */ 24 25 26 #include <string> 27 #include <iostream> 28 #include <fstream> 29 30 using namespace std; 31 #include "student.h" 32 33 int main(void) { 34 fstream students; 35 Student **sInfo; 36 int numStudents, cnt=0, i; 37 double num; 38 string studentType, studentName, studentCountry; 39 40 students.open("students.in", ios::in); 41 students >> numStudents; 42 sInfo = new Student*[numStudents]; 43 // This doesn't work with Sun Workshop 6.0. 44 // Student *sInfo[numStudents]; 45 while (cnt<numStudents) { 46 students >> studentType >> studentName >> studentCountry >> num; 47 if (students.eof()) break; 48 if (studentType=="exchange") { 49 sInfo[cnt]=new ExchangeStudent(num); 50 // sInfo[cnt]=new ExchangeStudent; 51 // ((ExchangeStudent *) sInfo[cnt])->setNumCourses(num); 52 } else if (studentType=="credit") { 53 sInfo[cnt]=new CreditStudent((int) num); 54 } else { 55 cout << "Unknown student type: " << studentType << "\n"; 56 students.close(); 57 return(-1); 58 } 59 sInfo[cnt]->setName(studentName); 60 sInfo[cnt]->setCountry(studentCountry); 61 cnt++; 62 } 63 students.close(); 64 65 for (i=0;i<cnt;i++) { 66 sInfo[i]->Display(); 67 delete sInfo[i]; 68 } 69 return(0); 70 } |