Download presentation
Presentation is loading. Please wait.
Published by轮用 赖 Modified over 7 years ago
1
Lab 6 Instructions You can use g++ on build server, visual studio on local machine or your preferred C++ IDE. Important Note: For your grade, please show me the result after you finish all the tasks. Make-Up Policies: If you cannot finish the drill in the lab, you can go back to work on it. You can send me (including result screenshot and source code) or show me in next lab.
2
Drill Modify the previous drill to use the framework on page 152 and use error() to throw an exception and print an error message if the temperature is below absolute zero. Step1 :Use a switch statement (like page 105) to write a program to convert between Fahrenheit and Celsius: if you input 22.5C it outputs 72.5F, and if you input 72.5F it outputs 22.5C Equations: C = (F -32) * 5/9 F = C * 9/5 + 32
3
Drill Step 2 : If the input temperature is under absolute zero ( Fahrenheit or Celsius), using error() function in “std_lib_facilities_4.h” to raise a runtime error. To ensure your code can properly handle errors, you can refer to try-catch statement in textbook Page If you can not use std library, can need to write your own error function: void error(string s){ throw runtime_error(s); }
4
Drill Example of try-catch statement If any error in the scope of try, the program will go you catch part. int main(){ try{ //our program } catch (exception &error){ cerr << “error:” << error.what() << ‘\n’;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.