legolas93
07-02-2012, 11:39
/*
* TestGradeBook.cpp
*
* Created on: 07/feb/2012
* Author: andrea
*/
#include <iostream>
#include "GradeBook.h"
using namespace std;
int main()
{
GradeBook gradeBook1("Il corso uno è troppo lunga da scrivere e quindi verra automaticamente tagliato");
gradeBook1.displayCourse();
cout << "\n";
gradeBook1.inputGrades();
gradeBook1.displayGradeReport();
return 0;
}
/*
* GradeBook.h
*
* Created on: 07/feb/2012
* Author: andrea
*/
#include <string>
using namespace std;
class GradeBook{
private:
string courseName;
string instructorName;
int aCount;
int bCount;
int cCount;
int dCount;
int eCount;
int fCount;
public:
void setCourseName(string);
string getCourseName();
GradeBook(string);
void displayCourse();
void determineClassAverage();
void inputGrades();
void displayGradeReport();
};
/*
* GradeBook.cpp
*
* Created on: 07/feb/2012
* Author: andrea
*/
#include <iostream>
#include <cstdio>
#include "GradeBook.h"
using namespace std;
void GradeBook::setCourseName(string name)
{
if(name.length() <= 25) courseName = name;
else
{
courseName = name.substr(0,25);
cout << "Nome troppo lungo" << endl;
}
}
string GradeBook::getCourseName()
{
return courseName;
}
/*
void GradeBook::setInstructorName(string name)
{
instructorName = name;
}
string GradeBook::getInstructorName(){
return instructorName;
}
*/
GradeBook::GradeBook(string name)
{
setCourseName(name);
aCount = 0;
bCount = 0;
cCount = 0;
dCount = 0;
fCount = 0;
}
void GradeBook::displayCourse()
{
cout << getCourseName() << endl;
}
void GradeBook::determineClassAverage()
{
int gradeCounter = 1;
int total, grade;
total = 0;
while(gradeCounter<=10)
{
cout << "Enter grade: " << endl;
cin >> grade;
total = total + grade;
gradeCounter = gradeCounter +1;
}
cout << "The average is " << (total/10);
}
void GradeBook::inputGrades()
{
int grade;
cout << "Enter the Letter Grade: " << endl << "Enter the EOF character to end input " << endl;
while ((grade = cin.get()) != EOF){
switch (grade)
{
case 'a':
case 'A':
aCount++;
break;
case 'b':
case 'B':
bCount++;
break;
case 'c':
case 'C':
cCount++;
break;
case 'd':
case 'D':
dCount++;
break;
case 'e':
case 'E':
eCount++;
break;
case 'f':
case 'F':
fCount++;
break;
default:
cout << "Incorrect Letter Grade entered" << "\n Enter a new grade: " << endl;
break;
}
}
}
void GradeBook::displayGradeReport(){
cout << "\n\nNumber of students who received each Letter Grade:"
<< "\nA: " << aCount
<< "\nB: " << bCount
<< "\nC: " << cCount
<< "\nD: " << dCount
<< "\nE: " << eCount
<< "\nF: " << fCount
<< endl;
}
Questo è l'output
Nome troppo lungo
Il corso uno è troppo lu
Enter the Letter Grade:
Enter the EOF character to end input
a
Incorrect Letter Grade entered
Enter a new grade:
d
Incorrect Letter Grade entered
Enter a new grade:
a
Incorrect Letter Grade entered
Enter a new grade:
A
Incorrect Letter Grade entered
Enter a new grade:
:muro:
Perchè mi dice che anche caratteri come A e a sono sbagliati :confused:
Avete qualche idea ragazzi?
* TestGradeBook.cpp
*
* Created on: 07/feb/2012
* Author: andrea
*/
#include <iostream>
#include "GradeBook.h"
using namespace std;
int main()
{
GradeBook gradeBook1("Il corso uno è troppo lunga da scrivere e quindi verra automaticamente tagliato");
gradeBook1.displayCourse();
cout << "\n";
gradeBook1.inputGrades();
gradeBook1.displayGradeReport();
return 0;
}
/*
* GradeBook.h
*
* Created on: 07/feb/2012
* Author: andrea
*/
#include <string>
using namespace std;
class GradeBook{
private:
string courseName;
string instructorName;
int aCount;
int bCount;
int cCount;
int dCount;
int eCount;
int fCount;
public:
void setCourseName(string);
string getCourseName();
GradeBook(string);
void displayCourse();
void determineClassAverage();
void inputGrades();
void displayGradeReport();
};
/*
* GradeBook.cpp
*
* Created on: 07/feb/2012
* Author: andrea
*/
#include <iostream>
#include <cstdio>
#include "GradeBook.h"
using namespace std;
void GradeBook::setCourseName(string name)
{
if(name.length() <= 25) courseName = name;
else
{
courseName = name.substr(0,25);
cout << "Nome troppo lungo" << endl;
}
}
string GradeBook::getCourseName()
{
return courseName;
}
/*
void GradeBook::setInstructorName(string name)
{
instructorName = name;
}
string GradeBook::getInstructorName(){
return instructorName;
}
*/
GradeBook::GradeBook(string name)
{
setCourseName(name);
aCount = 0;
bCount = 0;
cCount = 0;
dCount = 0;
fCount = 0;
}
void GradeBook::displayCourse()
{
cout << getCourseName() << endl;
}
void GradeBook::determineClassAverage()
{
int gradeCounter = 1;
int total, grade;
total = 0;
while(gradeCounter<=10)
{
cout << "Enter grade: " << endl;
cin >> grade;
total = total + grade;
gradeCounter = gradeCounter +1;
}
cout << "The average is " << (total/10);
}
void GradeBook::inputGrades()
{
int grade;
cout << "Enter the Letter Grade: " << endl << "Enter the EOF character to end input " << endl;
while ((grade = cin.get()) != EOF){
switch (grade)
{
case 'a':
case 'A':
aCount++;
break;
case 'b':
case 'B':
bCount++;
break;
case 'c':
case 'C':
cCount++;
break;
case 'd':
case 'D':
dCount++;
break;
case 'e':
case 'E':
eCount++;
break;
case 'f':
case 'F':
fCount++;
break;
default:
cout << "Incorrect Letter Grade entered" << "\n Enter a new grade: " << endl;
break;
}
}
}
void GradeBook::displayGradeReport(){
cout << "\n\nNumber of students who received each Letter Grade:"
<< "\nA: " << aCount
<< "\nB: " << bCount
<< "\nC: " << cCount
<< "\nD: " << dCount
<< "\nE: " << eCount
<< "\nF: " << fCount
<< endl;
}
Questo è l'output
Nome troppo lungo
Il corso uno è troppo lu
Enter the Letter Grade:
Enter the EOF character to end input
a
Incorrect Letter Grade entered
Enter a new grade:
d
Incorrect Letter Grade entered
Enter a new grade:
a
Incorrect Letter Grade entered
Enter a new grade:
A
Incorrect Letter Grade entered
Enter a new grade:
:muro:
Perchè mi dice che anche caratteri come A e a sono sbagliati :confused:
Avete qualche idea ragazzi?