/* * styleGuide.cpp * Lawrence Chan * 12/28/2018 * edited by Tyler Calabrese Sep/02/2020 * edited by Tyler Calabrese Jan/27/2022 * - correct format of inline comment on line 80 * COMP 15 HW 0 * Documentation example * * Includes a function for the Student class that allows a user to look up one * of a student's friends and print any stored information about them. */ /************** headers ************** * * As shown above, header comments should be on top of every file you * submit, regardless of who wrote the file. This promotes * consistency between homeworks and gets you into a good habit of * header information. It should include the * * name of the file, * your name (and creator if you are not the creator), * class and homework #, * assignment or program title, * date, * purpose * * The purpose should adequately describe the file so readers can know, at a * glance, whether the code in the file fits their needs and, if so, some * basic information about how to use it. * * (Above, "for the Student class" is an important indication of how this code * is meant to be used, and the rest of the 'purpose' section describes what * this code is for.) */ /************** functions ************** * Functions should be preceeded by a comment describing: * * - the function's purpose * - its parameters (write "nothing" if there are no parameters) * - what it returns (write "nothing" if the function is void) * - what effects it has (e. g., input/output, changes to mutable data) * - errors the function detects (and what it does) * - errors the function does not detect (e. g., doesn't check for NULL) * * Along with these necessary components, other information * should be included as necessary (eg. memory allocation, * invariants, weird things you're doing, lingering bugs) to provide * estra information to the reader. Parameters and returns should * be relevant to the function --- don't just write "string"! * What is the string? What does it describe? This additional * information is critical for understanding. * * In-function comments should be used when a block of code is * particularly complicated (maybe it exemplifies a central concept * from lecture) or, despite your best efforts, it remains difficult * to read. Note that you might be overcomplicating things if you * find that much of your code is unreadable without in-function comments. */ /************** sample function **************/ /* printFriendInfo * Purpose: print info about a friend, given their name * Parameters: the friend's name * Returns: true if found or false if not found * Effects: Print information to cout if found * otherwise print a "not found" message to cerr */ bool Student::printFriendInfo(string friendName) { bool found = false; // iterate to find friend, exit the loop and save the index if found for (int idx = 0; not found and idx < size; idx++) { if (friends[idx].name == friendName) { found = true; // idx is incremented with each iteration, so we'll need to // offset that because it will increment one more time idx--; } } // print out if found; idx stores the friend's index in the array if (found) { cout << friends[idx].name << endl; cout << friends[idx].age << endl; cout << friends[idx].height << endl; return true; } else { cerr << friendName << " not found!" << endl; return false; } } /* * Notice all binary operators, including assignments, * are space-separated: * * CORRECT: int x = 5; * INCORRECT: int x=5; * INCORRECT: int x =5; * INCORRECT: int x= 5; * * But unary operators are not: * CORRECT: i++; * INCORRECT: i ++; */