#include <fstream>
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
double gradePoint;
ofstream fout;
while(true)
{
cout << "What is your grade [0-4.0]? ";
cin >> gradePoint;
cin.ignore(1000,10);
// fill the code to separate out
// students' grade point are above 3.0
// AND
// students' grade point are below 2.0
cout << "your grade point is " << gradePoint << endl;
fout.open("roster2.txt", ios::app);
if(!fout.good()) throw "I/O Error";
fout << gradePoint << endl;
fout.close();
} // while
return 0;
}
Thursday, March 17, 2011
Tuesday, March 15, 2011
chapter 7
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string subject;
char grade;
double gradePoint;
ofstream fout;
while(true)
{
cout << "What is the subject? ";
getline(cin,subject);
cout << "What is your grade [A-F]? ";
cin >> grade;
cin.ignore(1000,10);
if (toupper(grade) == 'A')
{
gradePoint = 4.0;
}
else
{
if (toupper(grade) == 'B')
{
gradePoint = 3.0;
}
else
{
if (toupper(grade) == 'C')
{
gradePoint = 2.0;
}
else
{
if (grade == 'D' || grade == 'd')
{
gradePoint = 1.0;
}
else
{
gradePoint = 0;
break;
}
}
}
} // A !A
cout << "your grade point is " << gradePoint << endl;
fout.open("gradePointList.txt", ios::app);
// if(!fout.good()){ throw "I/O Error";}
if(!fout.good()) throw "I/O Error";
fout << gradePoint << endl;
fout.close();
} // while
return 0;
}
#include <string>
#include <cctype>
using namespace std;
int main()
{
string subject;
char grade;
double gradePoint;
ofstream fout;
while(true)
{
cout << "What is the subject? ";
getline(cin,subject);
cout << "What is your grade [A-F]? ";
cin >> grade;
cin.ignore(1000,10);
if (toupper(grade) == 'A')
{
gradePoint = 4.0;
}
else
{
if (toupper(grade) == 'B')
{
gradePoint = 3.0;
}
else
{
if (toupper(grade) == 'C')
{
gradePoint = 2.0;
}
else
{
if (grade == 'D' || grade == 'd')
{
gradePoint = 1.0;
}
else
{
gradePoint = 0;
break;
}
}
}
} // A !A
cout << "your grade point is " << gradePoint << endl;
fout.open("gradePointList.txt", ios::app);
// if(!fout.good()){ throw "I/O Error";}
if(!fout.good()) throw "I/O Error";
fout << gradePoint << endl;
fout.close();
} // while
return 0;
}
Thursday, February 24, 2011
C++ exception process
// exceptions
#include <iostream>
using namespace std;
int main () {
try
{
throw 20;
}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main () {
try
{
throw 20;
}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e << endl;
}
return 0;
}
Tuesday, January 25, 2011
Subscribe to:
Comments (Atom)