Esempio n. 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;
}
Esempio n. 2
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;
}
Esempio 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;
}
Esempio n. 4
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;
}
Esempio n. 6
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;
}
Esempio n. 7
0
int main() {
  try {
    Student_info record;
    record.grade();
  } catch (domain_error e) {
    cout << e.what() << endl;
  }

  return 0;
}
Esempio n. 8
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;
}
Esempio n. 9
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;
}
Esempio n. 11
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;
}
Esempio n. 12
0
double grade_aux(const Student_info& s)
{
    return s.grade();
}
Esempio n. 13
0
double average_grade(const Student_info& s)
{
    return s.average_grade();
}
Esempio n. 14
0
bool fgrade(Student_info& s)
{
    return s.grade() < 60;
}
Esempio n. 15
0
bool did_all_hw(const Student_info& s)
{
    return s.valid();
}
bool compare(const Student_info& x, const Student_info& y)
{
    return x.name() < y.name(); // Modified for class Student_info Ch. 9
}
bool compare(const Student_info& x, const Student_info& y)
{
    return x.name() < y.name();
}
Esempio n. 18
0
// median of the nonzero elements of s.homework or 0 if no such elements exist
double optimistic_median(const Student_info& s)
{
    return s.median_grade();
}
Esempio n. 19
0
bool compare(Student_info& a, Student_info& b) {
        return a.name() < b.name();
}
Esempio n. 20
0
int main() {
  Student_info record;
  if (record.valid()) record.grade();
  
  return 0;
}