Exemplo n.º 1
0
int main()
{
	vector<Student_info> students;
	Student_info record;
	string::size_type maxlen = 0;

	// read and store the data
	while (record.read(cin)) {
		maxlen = max(maxlen, record.name().size());
		students.push_back(record);
	}

	// alphabetize the student records
	sort(students.begin(), students.end(), Student_info::compare);

	// write the names and grades
	for (vector<Student_info>::size_type i = 0;
	     i != students.size(); ++i) {
		cout << students[i].name()
		     << string(maxlen + 1 - students[i].name().size(), ' ');
		try {
			double final_grade = students[i].grade();
			streamsize prec = cout.precision();
			cout << setprecision(3) << final_grade
			     << setprecision(prec) << endl;
		} catch (domain_error e) {
			cout << e.what() << endl;
		}
	}
	return 0;
}
Exemplo n.º 2
0
int main()
{

	vector<Student_info> students;
	Student_info record;
	string::size_type maxlen = 0;
	
	while(record.read(cin)) {
		maxlen = max(maxlen,record.name().size());
		students.push_back(record);
	}

	sort(students.begin(),students.end(),compare);
	for(int i=0;i<students.size();++i) {
		cout << students[i].name()
			<< string(maxlen+1-students[i].name().size(),' ');
		try {
			double finalgrade = students[i].grade();
			cout << setprecision(3) << finalgrade << endl;
		} catch (domain_error e) {
			cout << e.what() << endl;
		}
	}

	return 0;
}
Exemplo n.º 3
0
int main(int argc, const char *argv[])
{
    vector<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;

    while (record.read(cin)) {
        students.push_back(record);
        maxlen = max(maxlen, record.name().size());
    }

    for (vector<Student_info>::size_type i = 0; i != students.size(); i++) {
        cout << "Has student " << students[i].name() << " made any work?";
            if (students[i].valid()) {
                cout << " yes" << endl;
            } else {
                cout << " no" << endl;
            }
    }
    Core c1;
    c1.valid();
    cout << "Has student c1 made any work?";
    if (c1.valid()) {
        cout << " yes" << endl;
    } else {
        cout << " no" << endl;
    }

    return 0;
}
Exemplo n.º 4
0
int main(int argc, const char *argv[])
{
    Vec<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;

    while (record.read(cin)) {
        maxlen = max(maxlen, record.name().size());
        students.push_back(record);
    }

    //  
    sort(students.begin(), students.end(), compare);

    for (Vec<double>::size_type i = 0; i != students.size(); i++) {
        cout << students[i].name() << string(maxlen + 1 - students[i].name().size(), ' ');
        try {
            double final_grade = students[i].grade();
            streamsize prec = cout.precision();
            cout << setprecision(3) << final_grade << setprecision(prec) << endl;
        } catch (domain_error e) {
            cout << e.what() << endl;
        }
    }
    return 0;
}
Exemplo n.º 5
0
int main(int argc, const char *argv[])
{
    vector<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;

    while (record.read(cin)) {
        students.push_back(record);
        maxlen = max(maxlen, record.name().size());
    }

    for (vector<Student_info>::size_type i = 0; i != students.size(); i++) {
        cout << "Has student " << students[i].name() << " completed the thesis(for graduate) or homework(for undergraduate)?";
            if (students[i].complete()) {
                cout << " yes" ;
                cout << " grade: " << students[i].grade() << " " << students[i].letter_grade() << endl;
            } else {
                cout << " no" << endl;
            }
    }
    Core c1;
    c1.valid();
    cout << "Has student c1 made any work?";
    if (c1.valid()) {
        cout << " yes" << endl;
    } else {
        cout << " no" << endl;
    }

    return 0;
}
int main()
{
    vector<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;   // the length of the longest name

    // read input file (added for 13-1)
    ifstream studentFile("students.txt");

    // read and storea all the student's data
    // Invariant: students contains all the student records read so far
    //            maxlen contains the length of the longest name in students
    while (record.read(studentFile)) { // Modified for class Student_info Ch. 9
        // find length of the longest name
        maxlen = max(maxlen, record.name().size());
        students.push_back(record);
    }

    cout << "sort function" << endl;
    // alphebetize the student records
    sort(students.begin(), students.end(), Student_info::compare);

    cout << "write loop" << endl;
    // write the names and grades
    for (vector<Student_info>::size_type i = 0; i != students.size(); i++) {
        // write the name, padded on the right to maxlen + 1 characters
        cout << students[i].name() << string (maxlen + 1 - students[i].name().size(), ' ');
        string validity = students[i].valid() ? "valid" : "not valid";
        cout << validity << endl;

        // compute and write the grade
        try {
            double final_grade = students[i].grade();
            streamsize prec = cout.precision();
            cout << setprecision(3) << final_grade
                    << setprecision(prec) << endl;
        } catch (domain_error e) {
            cout << e.what() << endl;
        }
    }

    return 0;
}
Exemplo n.º 7
0
int main(int argc, const char *argv[])
{
    vector<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;

    while (record.read(cin)) {
        students.push_back(record);
        maxlen = max(maxlen, record.name().size());
    }

    
    cout << "student " << students[0].name() << " grade: " << students[0].grade() << " " << students[0].letter_grade() << endl;
    cout << "student " << students[1].name() << " grade: " << students[1].grade() << " " << students[1].letter_grade() << endl;
    cout << "student " << students[2].name() << " grade: " << students[2].grade() << " " << students[2].letter_grade() << endl;
    cout << "student " << students[3].name() << " grade: " << students[3].grade() << " " << students[3].letter_grade() << endl;
    cout << "student " << students[4].name() << " grade: " << students[4].grade() << " " << students[4].letter_grade() << endl;
    cout << "Has student " << students[4].name() << " passed?";
    if (students[4].grade() >= 60) {
        cout << " yes" << endl;
    } else {
        cout << " no" << endl;
    }
    cout << "student " << students[5].name() << " grade: " << students[5].grade() << " " << students[5].letter_grade() << endl;
    cout << "Has student " << students[5].name() << " passed?";
    if (students[5].grade() >= 60) {
        cout << " yes" << endl;
    } else {
        cout << " no" << endl;
    }
 
    Core c1;
    c1.valid();
    cout << "Has student c1 made any work?";
    if (c1.valid()) {
        cout << " yes" << endl;
    } else {
        cout << " no" << endl;
    }

    return 0;
}
Exemplo n.º 8
0
bool compare(Student_info& a, Student_info& b) {
        return a.name() < b.name();
}
bool compare(const Student_info& x, const Student_info& y)
{
    return x.name() < y.name();
}
bool compare(const Student_info& x, const Student_info& y)
{
    return x.name() < y.name(); // Modified for class Student_info Ch. 9
}