ECCS 1611 – Programming 1 Lab 8 – Problets and More Functions Part A – Problets Problets are on‐line tutorials to help you with mastering various aspects of programming in C++. If you need a refresher on how to use Problets please refer to Lab 2. For this lab you will be using the Function Behavior tutor module. Please remember to save the problet completion page in your Dropbox folder; see Lab 2 or a lab assistant if you need assistance. When all problets are completed, please call over either Dr. Estell or one of the lab assistants and have your lab checksheet signed. Part B – Programming practice with iteration and random numbers. Please write the following programs using Visual Studio. When completed, please demonstrate each program to either Dr. Estell or a lab assistant. Specified problems are derived from the textbook, pages 240‐241. P5.21 Leap years. Write a program that, when given a year, determines whether or not it is a leap year through use of the function bool isLeapYear(int year) that tests whether a year is a leap year: that is, a year with 366 days. Leap years are necessary to keep the calendar synchronized with the sun because the earth revolves around the sun once every 365.25 days. Actually, that figure is not entirely precise, and for all dates after 1582 the Gregorian correction applies. Usually years that are divisible by 4 are leap years, for example 1996. However, years that are divisible by 100 (for example, 1900) are not leap years, but years that are divisible by 400 are leap years (for example, 2000). Years should be requested from the user via a loop construct for acquiring test data. Example run (with user input indicated with bold italics): Enter the year or Q to quit: 2011 is not a leap year. Enter the year or Q to quit: 2012 is a leap year. Enter the year or Q to quit: 1900 is not a leap year. Enter the year or Q to quit: 2000 is a leap year. Enter the year or Q to quit: 2011 2012 1900 2000 Q P5.22 Write a program that converts a Roman number such as MCMLXXVIII to its decimal number representation. First write the function int romanToInt(char r) that yields the numeric value of the passed Roman numeral character. Then implement the following algorithm with the function int convertRomanToInt(string s): total = 0 While the roman number string is not empty If the first character has a larger or equal value than the second, or the string has length 1 Add value(first character) to total. Remove the character. Else Add the quantity: value(second character) - value(first character) to total. Remove both characters. Provide a program that tests your functions via a loop construct for acquiring testing data. Example run (with user input indicated with bold italics): Enter Roman number or I = 1 Enter Roman number or V = 5 Enter Roman number or X = 10 Enter Roman number or L = 50 Enter Roman number or C = 100 Enter Roman number or D = 500 Enter Roman number or M = 1000 Enter Roman number or MCMLXII = 1962 Enter Roman number or MDCCCLXXXVIII = 1888 Enter Roman number or Q to quit: I Q to quit: V Q to quit: X Q to quit: L Q to quit: C Q to quit: D Q to quit: M Q to quit: MCMLXII Q to quit: MDCCCLXXXVIII Q to quit: Q
© Copyright 2026 Paperzz