示例#1
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;
}
示例#2
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;
}
int main()
{
    // students who did and didn't do all of their homework
    vector<Student_info> did, didnt;

    // read the students records and partition them
    Student_info student;
    while (student.read(cin)) {
        if (student.did_all_hw())
            did.push_back(student);
        else
            didnt.push_back(student);
    }

    // verify that the analysis will show us something
    if (did.empty()) {
        cout << "No student did all the homework!" << endl;
        return 1;
    }
    if (didnt.empty()) {
        cout << "Every student did all the homework!" << endl;
        return 1;
    }

    // do the analyses
    write_analysis(cout, "median", median_analysis, did, didnt);
    write_analysis(cout, "average", average_analysis, did, didnt);
    write_analysis(cout, "median of homework turned in", optimistic_median_analysis, did, didnt);

    return 0;
}
示例#4
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;
}
示例#5
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;
}
示例#6
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;
}
示例#7
0
int main()
{
    vector<Student_info> students;
    Student_info s;

    while(s.read(cin))
        students.push_back(s);

    sort(students.begin(), students.end(), Student_info::compare);

    cout << frame(histogram(students)) << endl;
    return 0;
}
示例#8
0
int main()
{

    // students who did and didn't do all of their hw
    vector<Student_info> did, didnt;

    // read the student records and partition them
    Student_info student;
    while (student.read(cin)) {
        if (did_all_hw(student))
            did.push_back(student);
        else
            didnt.push_back(student);
    }

    // check that both groups contain data
    //if (did.empty()) {
        //cout << "No student did all the homework!" << endl;
        //return 1;
    //}
    //if (didnt.empty()) {
        //std::cout << "Every student did all the homework!" << std::endl;
        //return 1;
    //}

    // do the analysis
    write_analysis(cout, "median", grade_aux, did, didnt);
    cout << "Created: " << Student_info::num_create << endl;
    cout << "Copied: " << Student_info::num_copy << endl;
    cout << "Destroyed: " << Student_info::num_destr << endl;
    cout << "Assigned: " << Student_info::num_asmt << endl;
    write_analysis(cout, "average", average_grade, did, didnt);
    cout << "Created: " << Student_info::num_create << endl;
    cout << "Copied: " << Student_info::num_copy << endl;
    cout << "Destroyed: " << Student_info::num_destr << endl;
    cout << "Assigned: " << Student_info::num_asmt << endl;
    write_analysis(cout, "median of hw turned in", optimistic_median, did, didnt);
    cout << "Created: " << Student_info::num_create << endl;
    cout << "Copied: " << Student_info::num_copy << endl;
    cout << "Destroyed: " << Student_info::num_destr << endl;
    cout << "Assigned: " << Student_info::num_asmt << 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;
}
示例#10
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;
}