PRACTICAL – 13.1
Write a program to demonstrate how parameters are passed to the base class constructor via the derived class constructor
#include <iostream>using namespace std;class Parent{int parent_num;public:Parent(int a){parent_num = a;}void print_p(){cout << parent_num << endl;}};class Child : public Parent{int child_num;public:Child(int a, int b) : Parent(a){child_num = b;}void print_c(){cout << child_num << endl;}};int main(){Child r(22, 14);r.print_p();r.print_c();return 0;}
Practical 13.2.1
Write a program to use the following functions: Put(), Get().
#include <iostream>using namespace std;int main(){int count = 0;char c;cout << "Intput Text : ";cin.get(c);while (c != '\n'){cout.put(c);count++;cin.get(c);}cout << "Number of Charecter is " << count << endl;return 0;}
Practical 13.2.2
Write a program to use the following functions: Getline(), Write().
#include <iostream>#include <string>using namespace std;int main(){int count = 0;char *c;cout << "Intput Text : ";cin.getline(c, 3);cout.write(c, 2);cout << c;return 0;}
Practical 13.3.1
Write a program to produce formatted output using the following functions: Width(), Precision(), Fill(), Setf(), Unsetf()
#include <iostream>using namespace std;int main(){float f = 1.2222222;cout.precision(2);cout << f << endl;cout.fill('&');cout.setf(ios::left, ios::adjustfield);cout.width(10);cout << "123" << endl;return 0;}
0 Comments