int main() { std::vector<Student_info> students; Student_info record; std::string::size_type maxlen = 0; std::cout << "Please enter each student's record on a line" << std::endl; std::cout << "<Name> <midterm> <final> <hw1> <hw2> ... " << std::endl; std::cout << "E.g. Smith 78 87 67 75 82" << std::endl; std::cout << "Enter end-of-file (ctrl+D) when done" << std::endl; while (read(std::cin, record)) { // find length of longest name maxlen = std::max(maxlen, record.name.size()); students.push_back(record); } // alphabetize the student records sort(students.begin(), students.end(), compare); // write the names and grades for(std::vector<Student_info>::size_type i = 0;i != students.size(); ++i){ // write the name, padded on the right to maxlen + 1 characters std::cout << students[i].name << std::string(maxlen + 1 - students[i].name.size(), ' '); // compute and write the grade try { double final_grade = grade(students[i]); std::streamsize prec = std::cout.precision(); std::cout << std::setprecision(3) << final_grade << std::setprecision(prec); } catch (std::domain_error e) { std::cout << e.what(); } std::cout << std::endl; } return 0; }
void boundary()//开始界面 { system("cls"); char s; color(14); printf("\t\t欢迎来玩!!\n\n"); printf("\t\t1:开始\n\n"); printf("\t\t2:查看成绩\n\n"); printf("\t\t3:退出\n\n"); printf("\t\t请选择:"); s = getche(); switch (s) { case '1': play(); break; case '2': grade(); break; case '3': end(); break; } }
int main() { std::vector<Student_info> students; Student_info record; std::string::size_type maxlen = 0; while(read(std::cin, record)) { maxlen = std::max(maxlen, record.name.size()); students.push_back(record); } std::sort(students.begin(), students.end(), cmp); for(std::vector<Student_info>::size_type i=0; i!=students.size(); ++i) { std::cout << students[i].name << std::string(maxlen + 1 - students[i].name.size(), ' '); try { double final_grade = grade(students[i]); std::streamsize prec = std::cout.precision(); std::cout << std::setprecision(3) << final_grade << std::setprecision(prec); } catch(std::domain_error e) { std::cout << e.what(); } } return 0; }
void EngineerExam::on_checkQuestions_clicked() { if (this->type == 1) { QuestionWidget *qw = static_cast<QuestionWidget*>(ui->stackedWidget->currentWidget()); qw->isSelectedAnswerCorrect(); return; } int correct = 0; for (int i = 0; i < ui->stackedWidget->count(); ++i) { QuestionWidget *qw = static_cast<QuestionWidget*>(ui->stackedWidget->widget(i)); correct += qw->isSelectedAnswerCorrect(); } double percent = (correct * 1.0) / (questionsList.size() * 1.0) * 100; qDebug() << correct; ui->timer->stop(); if (type == 0) { QMessageBox::information(0, trUtf8("Wynik"), trUtf8("Odpowiedziałeś poprawnie na %1 z %2 pytań. Procentowo to %3. Otrzymujesz %4.") .arg(correct) .arg(questionsList.count()) .arg(percent) .arg(grade(percent))); } }
double grade(double midterm_exam, double final_exam, const std::vector<double> &hw) { if(hw.size() == 0) { throw std::domain_error("Student has done no homework."); } return grade(midterm_exam, final_exam, median(hw)); }
int main() { int i; while (scanf("%d", &i) != EOF) { printf ("%d\n", grade(i)); } return 0; }
void Student::outputgrade(std::ostream &ostr,bool flag_b4_moss,Student *lowest_d) const { std::string g = grade(flag_b4_moss,lowest_d); std::string color = GradeColor(g); if (moss_penalty < -0.01) { ostr << "<td align=center bgcolor=" << color << ">" << g << " *</td>"; } else { ostr << "<td align=center bgcolor=" << color << ">" << g << "</td>"; } }
double grade_aux(const Student_info& s) { try { return grade(s); } catch (domain_error) { return grade(s.midterm, s.final, 0); } }
const Mark& Mark::display(int type)const{ if (type == DSP_GRADE){ std::cout << grade(); } else if (type == DSP_GPA){ std::cout <<setprecision(1) << fixed << gpa(); } else if (type == DSP_MARK){ std::cout << weightedMark(); } else{ std::cout << "Bad display type for a mark"; } return *this; }
static void parse_file(evaluation& e, const std::string& path) { csv_parser parser(path); size_t course_grade_key_i; std::vector<std::pair<std::string, size_t>> teacher_grade_key_is; { std::vector<std::string> line; if(!parser.read(line)) throw std::runtime_error("No headerline"); course_grade_key_i = find_course_grade_key(line, path); teacher_grade_key_is = find_teacher_grade_keys(line); if(teacher_grade_key_is.empty()) teacher_grade_key_is.emplace_back("all", find_teacher_grade_key(line, path)); } size_t i = 0; for(std::vector<std::string> line; parser.read(line); ++i) { if(line.size() > 1) { if(line.at(course_grade_key_i) != "") //Answer has not been filled in e.course_grade.ratings.push_back(boost::lexical_cast<double>(line.at(course_grade_key_i))); assert(teacher_grade_key_is.size() > 0); for(std::pair<std::string, size_t> teacher_p : teacher_grade_key_is) { std::string& teacher_str(teacher_p.first); size_t teacher_grade_key_i = teacher_p.second; if(line.at(teacher_grade_key_i) == "") //Answer has not been filled in continue; double teacher_grade = boost::lexical_cast<double>(line.at(teacher_grade_key_i)); if(e.teachers_grade.find(teacher_str) == e.teachers_grade.end()) e.teachers_grade.insert(std::make_pair(teacher_str, grade())); e.teachers_grade[teacher_str].ratings.emplace_back(teacher_grade); } } } }
void TetrisAI::search() { // Beam Search mSearchTimer.start(); mReady = false; mNewThread = false; multimap<int, PlayfieldNode> nodeMap; multimap<int, PlayfieldNode> newNodeMap; nodeMap.insert(make_pair(grade(mCurrentNode), mCurrentNode)); // Queue for (vector<int>::iterator it = mTetrominoQueue.begin(); it != mTetrominoQueue.begin() + mSearchDepth; it++) { // Current Map newNodeMap.clear(); for (multimap<int, PlayfieldNode>::iterator nit = nodeMap.begin(); nit != nodeMap.end(); nit++) { // New Node vector<PlayfieldNode> newSet = generate(nit->second, *it); // Adding to new Map for (vector<PlayfieldNode>::iterator vit = newSet.begin(); vit != newSet.end(); vit++) { newNodeMap.insert(make_pair(grade(*vit), *vit)); } } if (newNodeMap.size() > SEARCH_BEAM_WIDTH) { // Beaming multimap<int, PlayfieldNode>::iterator beamingIt = newNodeMap.begin(); advance(beamingIt, newNodeMap.size() - SEARCH_BEAM_WIDTH); newNodeMap.erase(newNodeMap.begin(), beamingIt); } nodeMap = newNodeMap; } // Best node is last node multimap<int, PlayfieldNode>::iterator bestNodeIt = nodeMap.end(); advance(bestNodeIt, -1); PlayfieldNode bestNode = bestNodeIt->second; // Constructing inputs vector<int> commands; PlayfieldPosition instruction = bestNode.mTetrominoPositions.at(0); for (int i = 0; i < instruction.rotation; i++) { commands.push_back(INPUT_CLOCKWISE); } PlayfieldPosition spawn = getSpawnPosition(instruction.ttype); int relativeX = instruction.x - spawn.x; int directionInput = INPUT_RIGHT; if (relativeX < 0) { directionInput = INPUT_LEFT; } for (int i = 0; i < abs(relativeX); i++) { commands.push_back(directionInput); } commands.push_back(INPUT_HARDDROP); execute(commands); int searchTime = mSearchTimer.getTicks(); mReady = true; //printf("Thinking time: %i\n", searchTime); }
double grade(const StudentInfo& StudentInfo){ return grade(StudentInfo.midScore, StudentInfo.finScore, StudentInfo.homework); }
double grade(double midScore, double finScore, const vector<double>& homework){ if(homework.size() == 0){ throw domain_error("student has done no homework!"); } return grade(midScore, finScore, median(homework)); }
int main() { int eng,mat,c,jav,db,tot,avg,rno; float per; //percentage will be float,decimal char name[100]; //student name system("cls"); printf("\n\nWelcome to student marksheet generation module!"); printf("\n===============================================\n\n"); //student input => name, roll number and marks printf("Enter your name: "); fgets(name,100,stdin); //scan name strtok(name,"\n"); //remove the trailing \n from name(stdin) to drop the new line printf("\nEnter your roll number: "); scanf("%d",&rno); printf("\n\nHello, %s Please enter your subjectwise marks out of 100: \n",name); printf("\nEnglish: "); scanf("%d",&eng); printf("\nMath: "); scanf("%d",&mat); printf("\nC Prog: "); scanf("%d",&c); printf("\nJava Prog: "); scanf("%d",&jav); printf("\nDatabase: "); scanf("%d",&db); if(eng > 100 || mat > 100 || c > 100 || jav > 100 || db > 100) //check validity of marks { //No marks can exceed 100 printf("\n\nInvalid marks entered. Must be out of 100."); } else { //proceed only if all marks are <=100 system("cls"); printf("\n\n\nGenerating Your Marksheet..."); printf("\n============================"); sleep(2); // freopen("marksheet.txt","w",stdout); printf("\n\nStudent Details:"); //Marksheet formatting printf("\n----------------"); printf("\n\nStudent Name: %s\nStudent Roll No.: %d",name,rno); //print name and roll no. printf("\n========================================\n"); printf("\nYour Subjectwise Marks:"); printf("\n-----------------------\n\n"); printf("English\tMaths\tC-Prog\tJava\tDatabase"); printf("\n\n%d/100\t%d/100\t%d/100\t%d/100\t%d/100",eng,mat,c,jav,db); printf("\n========================================\n"); tot = total(eng,mat,c,jav,db); //function call to total, returns total of all subjects printf("\n========================================"); printf("\nTotal Marks = %d/500",tot); //display total printf("\n========================================"); avg = avrg(tot); //function call to avrg, returns avg marks out of 100 printf("\nAverage Marks = %d/100",avg); //Display avg marks printf("\n========================================"); per = prcnt(tot); //function call to prcnt, returns a float value for percentage printf("\nPercentage: %.2f %%",per);//Display percent printf("\n========================================\n"); printf("\nGrade: "); grade(per,name);//Check and display grade } getche(); return 0; }
void grade_calculator::intialize_grade_table() { grade_table.push_back(grade("A", 4.0)); grade_table.push_back(grade("A-", 3.67)); grade_table.push_back(grade("B+", 3.33)); grade_table.push_back(grade("B", 3.0)); grade_table.push_back(grade("B-", 2.67)); grade_table.push_back(grade("C+", 2.33)); grade_table.push_back(grade("C", 2.0)); grade_table.push_back(grade("C-", 1.67)); grade_table.push_back(grade("D+", 1.33)); grade_table.push_back(grade("D", 1.0)); grade_table.push_back(grade("F", 1.0)); }
if(hw.size() == 0) { throw std::domain_error("Student has done no homework."); } return grade(midterm_exam, final_exam, median(hw)); } student_info::student_info() : midterm_exam(0), final_exam(0), final_grade(0) { } student_info::student_info(std::istream &in) { read(in); } std::istream& student_info::read(std::istream &in) { in >> n >> midterm_exam >> final_exam; read_hw(in, homework); final_grade = grade(); return in; } double student_info::grade() const { return ::grade(midterm_exam,final_exam,homework); } bool compare(const student_info &x, const student_info &y) { return x.name() < y.name(); }