/*======== Fall 2025 - CS 111 Week 12 Lab Exercise - save as lab12.cpp date: 2025-11-14 ========*/ /*=== =====> ****************************** =====> TODAY's LAB is NOT TYPICAL !!! =====> Several PREVIOUSLY-WRITTEN-and-TESTED functions have =====> been copied here, =====> and you are going to ADD to the *main* function =====> as specified to complete an interactive front-end =====> that makes use of these already-tested functions! ===*/ /*--- USING pair-programming * COPY and PASTE the contents of this file into a file in the CS50 IDE named: lab12.cpp * ADD the parts asked for below *to* this file as specified (one student saying what to type, the other student typing it into the CS50 IDE) * each time you want to compile: in a CS50 terminal that is open to the folder CONTAINING this .cpp file, ("Open in Integrated Terminal"), type: g++ lab12.cpp -o lab12 * IF it compiles with no errors: to run: in that same CS50 terminal that is open to the folder CONTAINING this .cpp file, type: ./lab12 ******** * BUT, note!! Because the INTERACTIVE input in today's lab makes redirected output TRICKY, you do NOT need to submit a .txt file THIS time! ******** * Download a copy of your resulting lab12.cpp by right-clicking on its name in the file explorer on the left of the CS50 IDE, and use Gmail to MAIL a copy of this file to BOTH of you. * And, EACH of you should SUBMIT this file, *** lab12.cpp *** to Canvas BEFORE you leave lab. * REMEMBER to also answer the "Week 12 Lab Exercise - Pair-Programming Peer Review Survey" in Canvas, posted along with this lab exercise, by 11:59 pm TONIGHT (Friday, November 14) ---*/ /*--- by: PUT BOTH of YOUR NAMES HERE last modified: 2025-11-14 ---*/ #include <cstdlib> #include <iostream> #include <string> #include <cmath> using namespace std; /*--- COPIED from CS 111 - Week 10 Lecture 1 ---*/ /*=== signature: name_length: string string -> int purpose: expects a first name and a last name, and returns the total length of that "full" name (the total number of characters in the first name AND the last name) tests: name_length("Sally", "Rafael") == 11 name_length("John", "Doe") == 7 ===*/ int name_length(string f_name, string l_name) { return f_name.length() + l_name.length(); } /*--- COPIED from CS 111 - Week 10 Lab Exercise ---*/ /*--- signature: short_name: string string -> string purpose: expects a first name and a last name, and returns a shorter version of that full name made up of the first initial, a period, a blank, and the last name tests: short_name("Charlie", "Brown") == "C. Brown" short_name("Katherine", "Johnson") == "K. Johnson" ---*/ string short_name(string first_name, string last_name) { return first_name.substr(0, 1) + ". " + last_name; } /*--- COPIED from CS 111 - Week 10 Lecture 2 ---*/ /*=== signature: porridge_pref: double -> string purpose: expects a porridge temperature, and returns: * "mama-approved" if it is less than 50 degrees * "papa-approved" if it is more than 80 degrees * "baby-approved" if in [50, 80] tests: porridge_pref(13) == "mama-approved" porridge_pref(50) == "baby-approved" porridge_pref(60) == "baby-approved" porridge_pref(80) == "baby-approved" porridge_pref(212) == "papa-approved" ===*/ string porridge_pref(double porridge_temp) { if (porridge_temp < 50) { return "mama-approved"; } else if (porridge_temp <= 80) { return "baby-approved"; } else { return "papa-approved"; } } /*--- COPIED from CS 111 - Week 11 Lecture 2 ---*/ /*=== signature: describe_grade: char -> string purpose: expects a grade expressed as a char, and returns a string description for that grade, as follows: grade description ===== =========== 'A' or 'a' "Excellent" 'B' or 'b' "Very Good" 'C' or 'c' "Acceptable" 'T' or 't' "Try Again" anything else "Unrecognized Grade" tests: describe_grade('A') == "Excellent" describe_grade('B') == "Very Good" describe_grade('C') == "Acceptable" describe_grade('T') == "Try Again" describe_grade('a') == "Excellent" describe_grade('b') == "Very Good" describe_grade('c') == "Acceptable" describe_grade('t') == "Try Again" describe_grade('P') == "Unrecognized Grade" ===*/ string describe_grade(char letter_grade) { string grade_descr = ""; switch(letter_grade) { case 'A': case 'a': grade_descr = "Excellent"; break; case 'B': case 'b': grade_descr = "Very Good"; break; case 'C': case 'c': grade_descr = "Acceptable"; break; case 'T': case 't': grade_descr = "Try Again"; break; default: grade_descr = "Unrecognized Grade"; } return grade_descr; } /*--- interactive front-end making use of the functions above ---*/ int main() { cout << boolalpha; cout << endl; /*--- Try compiling and running lab12.cpp at this point -- you should just see an opening message, four partial, not-yet-complete messages, and a closing message. ---*/ /*--- (can CHANGE this little opening message if you want) ---*/ cout << "***************************" << endl; cout << "* a LITTLE about someone! *" << endl; cout << "***************************" << endl << endl; /*--- Declare TWO local variables appropriate for holding a person's FIRST name and LAST name: ---*/ /*--- Use cout to ask the user to enter a desired FIRST name, THEN use cin with >> and your local variable for a person's FIRST name to assign to that variable what the user enters: ---*/ /*--- Use cout to ask the user to enter a desired LAST name, then use cin with >> and your local variable for a person's LAST name to assign to that variable what the user enters: ---*/ cout << endl; cout << "The length of this person's name is: "; /*--- Use cout to print to the screen the value of the expression calling name_length with your now-filled local variables for a person's FIRST and LAST names: ---*/ cout << endl; cout << "The shortened version of this person's name is: "; /*--- Use cout to print to the screen the value of the expression calling short_name with those same local variables for a person's FIRST and LAST names: ---*/ cout << endl; /*--- Declare ONE local variable appropriate for holding a person's preferred porridge temperature: ---*/ /*--- Use cout to ask the user to enter that person's preferred porridge temperature, then use cin with >> and your local variable for a person's preferred porridge temperature to assign to that variable what the user enters: ---*/ cout << endl; cout << "Fun fact: this person's porridge temperature has the recommendation: " << endl << " "; /*--- Use cout to print to the screen the value of the expression calling porridge_pref with your now-filled local variable for a person's preferred porridge temperature: ---*/ cout << endl; /*--- Declare ONE local variable appropriate for holding a person's grade to be described: ---*/ /*--- Use cout to ask the user to enter that person's grade to be described, then use cin with >> and your local variable for a person's grade to be described to assign to that variable what the user enters: ---*/ cout << endl; cout << "The description for this person's grade is: "; /*--- Use cout to print to the screen the value of the expression calling describe_grade with your now-filled local variable for a person's grade to be described: ---*/ /*--- (can CHANGE this little closing message if you want) ---*/ cout << endl; cout << "***********************" << endl; cout << "* That's ALL for now! *" << endl; cout << "***********************" << endl << endl; return EXIT_SUCCESS; } /*--- Remember: once you have compiled and run these and are satisfied with them, * DOWNLOAD a copy of this file lab12.cpp, and use Gmail to E-MAIL a copy of this file to BOTH of you. * BOTH of you should submit your file *** lab12.cpp *** to Canvas BEFORE you leave lab. * ALSO answer the "Week 12 Lab Exercise - Pair-Programming Peer Review Survey" in Canvas, posted along with this lab exercise, by 11:59 pm TONIGHT (Friday, November 14) ---*/