- Type
- Quiz
- Course
- CS201P Introduction to Programming (Practical)
- Size
- PDF 232 KB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extensionSign in with the extension for 30 a day.
Preview text
Text from pages 1, 2, 3 of 32. Download the file for all 32 pages.
CS201-Lab-Exercise - this is the latest lab from cs201, you can practice it and also another cs students
Introduction to programming /c++ (Virtual University of Pakistan)
Scan to open on Studocu
CS201-Lab-Exercise - this is the latest lab from cs201, you can practice it and also another cs students
Introduction to programming /c++ (Virtual University of Pakistan)
Scan to open on Studocu
Lab # 13
You need to write a program in which the following concepts must be implemented. Write a template function name “Add” which accepts two arguments of the same type int, float, double from the user then add those arguments, return their sum and display them on the screen. Write a class named as firstClass, also write another class named as secondClass which should be nested inside the firstClass. Define a function named displayMessage inside the secondClass, this method should print the message “Inside the second class” on the screen. In the main function create the object of the secondClass and invoke the displayMessage method using the secondClass object.
Solution:
class firstClass {
public:
class secondClass { public: void displayMessage(){ cout<< " Function inside the inner class" <<endl;
template<class T> T Add (T x, T y) { return x + y;
int main() {
firstClass :: secondClass object; object.displayMessage();
int integerOne = 3, integerTwo = 5; float floatOne = 12.34, floatTwo = 894.4; double doubleOne = 1236.58, doubleTwo = 8945.685;
cout<< " Addition of Two integer Number is = " << Add(integerOne,integerTwo) <<endl; cout<< " Addition of Two floating point Number is = " << Add(floatOne,floatTwo) <<endl; cout<< " Addition of Two double Number is = " << Add(doubleOne , doubleTwo) <<endl;
return 0;
Related CS201P files
All CS201P files →Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.