

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
exercise questions for home work
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Q no 1
Create a function called swaps () that interchanges the values of the two arguments sent to it. (You will probably want to pass these arguments by
reference.) Make the function into a template, so it can be used with all numerical data types (char, int, float, and soon). Write a main () program to exercise the function with several types. Q No 2: Create a function that accept and swap the values of the array using template function. Q no 3: Write program that create a Stack with exception handlings methods. Q no 4: Write program that create a Stack with multiple catch blocks one for full Stack and second for empty Stack exception handlings methods
Write a function calculateAverage() which takes four int arguments which are marks for four courses in the semester and returns their average as a float. The calculateAverage() function should take only valid range for marks which is between 0 - 100. If the marks are out of range throw an OutOfRangeException - define this exception as a class Solved examples for exception handling #include
class OutOfRangeException {};
/*
return (m1 + m2 + m3 +m4 ) / 4.0; }
int main () { try { float avg = calculateAverage(79,90,100,90); cout << avg; }catch (OutOfRangeException ) { cerr << "marks out of range" << endl; } system("pause"); }