PRACTICAL – 4.1
Write a function that creates an array of user given size using new operator.
#include <iostream>using namespace std;class Array{public:void creatArray(int x){int *arr = new int[x];cout << "Enter data of Array : ";for (int i = 0; i < x; i++){cin >> arr[i];}for (int i = 0; i < x; i++){cout << arr[i] << endl;}}};int main(){Array r;r.creatArray(5);return 0;}
Practical 4.2
Define a class to represent a bank account. Include the members like name of the depositor, account number, type of account, and balance amount in the account. Make functions
(1)To assign initial values,
(2)To deposit an amount,
(3)To withdraw an amount after checking the balance,
(4)To display name and balance. Write a main program to test the program.
#include <iostream>#include <string>using namespace std;class Bank{private:string name;double acc_num;string typ_acc;int bal_amt;public:void creat_acc(){cout << "Enter Name : ";cin >> this->name;cout << "Enter Type of Account : ";cin >> this->typ_acc;cout << "Account creat succesfully ";}void ass_int_amt(){cout << "Enter intial amount : ";cin >> this->bal_amt;}void dep_amt(){int deposit;cout << "Enter Amout you want to deposit : ";cin >> deposit;this->bal_amt += deposit;}void witdrawl(){int wit_amt;cout << "Amount in your Account is : " << bal_amt;if (bal_amt > 0){cout << "How much you want to withdrawl : ";cin >> wit_amt;if (wit_amt < bal_amt){cout << "Withdrawl is done!!";bal_amt -= wit_amt;}else{cout << "Not Sufficient amount in your account !!" << endl<< "Enter again !! ";witdrawl();}}else{cout << "Not Sufficient amount in your account !!";}}void dis_name(){cout << "Name : " << name << endl<< "Balance : " << bal_amt;}};int main(){Bank customer[10];customer[1].creat_acc();customer[1].ass_int_amt();customer[1].dis_name();customer[1].dep_amt();customer[1].witdrawl();return 0;}
Practical 4.3
Create a C++ program to convert temperature in Fahrenheit to celcius and display. Use class.
#include <iostream>using namespace std;class temprature{public:float cal(int f){int c = (f - 32) * 5 / 9;return c;}};int main(){temprature x;cout << x.cal(104);return 0;}
0 Comments