0% found this document useful (0 votes)
93 views2 pages

Department of Computer Science: Bahria University, Lahore Campus

The document is a lab journal from Bahria University's Department of Computer Science for an Object Oriented Programming lab session. The lab focuses on exception handling in C++. The two tasks are to write programs that handle exceptions for invalid user input of lengths in feet/inches converted to centimeters and dates of birth entered in numeric form converted to month/day/year format, with custom exception classes for invalid values. The lab is worth a maximum of 10 marks and students must attempt both tasks to receive grading and feedback from the instructor.

Uploaded by

qfq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views2 pages

Department of Computer Science: Bahria University, Lahore Campus

The document is a lab journal from Bahria University's Department of Computer Science for an Object Oriented Programming lab session. The lab focuses on exception handling in C++. The two tasks are to write programs that handle exceptions for invalid user input of lengths in feet/inches converted to centimeters and dates of birth entered in numeric form converted to month/day/year format, with custom exception classes for invalid values. The lab is worth a maximum of 10 marks and students must attempt both tasks to receive grading and feedback from the instructor.

Uploaded by

qfq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Bahria University, Lahore Campus

Department of Computer Science


Lab Journal 13
(Spring 2020)

Course: Object Oriented Programming - Lab Date: _______________


Course Code: CSL-210 Max Marks: 10
Faculty’s Name: Ms. Zupash Awais

Name: _____________________ Enroll No: ___________________ Class:


______________

Objective(s):
Upon completion of this lab session, learners will be able to:
 Exception Handling in C++

Lab Tasks:

Task 1
Write a program that prompts the user to enter a length in feet and inches and outputs the
equivalent length in centimeters. If the user enters a negative number, throw and handle an
appropriate exception and prompt the user to enter another set of numbers.

#include<iostream>
#include<string>
using namespace std;
int main()

int feet = -1;

double total, inch, cent;

while (feet<0 || inch<0){


cout << "Please enter the number of Feet: ";
cin >> feet;
cout << "Please enter the number inch: ";
cin >> inch;

try

if (feet<0)

throw(feet);

if (inch<0)

throw(inch);
%
Enrollment Number: ____________________________

total = (feet * 12) + inch;

cent = total*2.54;

cout << feet << " feet and " << inch << " inch is "

<< cent << " centimeters" << endl;

catch (int feet)

cout << "You entered an invalid number for feet, please


try again." << endl;

catch (double inch)

{
cout << "You entered an invalid number for inch, please try
again." << endl;
}}
return 0;

Task 2
Write a program that prompts the user to enter a person’s date of birth in numeric form such
as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your
program must contain at least two exception classes: invalidDay and invalidMonth. If the
user enters an invalid value for day, then the program should throw and catch an
invalidDayobject. Similar conventions for the invalid values of month and year.

Lab Grading Sheet :


Max
Obtained
Task Mark Comments(if any)
Marks
s
1. 04
2. 06
Total 10 Signature

Note : Attempt all tasks and get them checked by your Lab Instructor.

Page 2 of 2

You might also like