Assignme
Assignme
Department of CS & IT
Assignment 04
Instructor Name: Miss Iqra Adnan
Course Title: Object Oriented Programming
Student Name:Arooj University ID: 70146896
int main() {
ifstream f("text.txt");
char c;
int ch = 0, v = 0;
while (f.get(c)) {
ch++;
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
v++;
}
}
cout << "Characters: " << ch << endl;
cout << "Vowels: " << v << endl;
return 0;
}
struct Customer {
int AccountNumber;
char Name[50];
float Amount;
};
int main() {
Customer c[3];
for (int i = 0; i < 3; i++) {
cin >> c[i].AccountNumber >> c[i].Name >> c[i].Amount;
}
ofstream out("Bank.txt", ios::binary);
out.write((char*)&c, sizeof(c));
out.close();
return 0;
}
class Country {
public:
int id;
char Name[50];
void get() {
cout<<"Enter id: ";
cin >> id ;
cout<<"Ente Name: ";cin>>Name;
}
void show() {
cout << id << " " << Name << endl;
}
};
int main() {
Country c;
c.get();
ofstream out("country.txt", ios::binary);
out.write((char*)&c, sizeof(c));
out.close();
Country d;
ifstream in("country.txt", ios::binary);
in.read((char*)&d, sizeof(d));
d.show();
in.close();
return 0;
}
Q4: Inheritance + Virtual Function
#include <iostream>
using namespace std;
class BankAccount {
public:
int AccountNumber;
float balance;
BankAccount(int a, float b) {
AccountNumber = a;
balance = b;
}
virtual void displayBalance() {
cout << balance << endl;
}
void deposit(float x) {
balance += x;
}
void withdraw(float x) {
balance -= x;
}
};
int main() {
BankAccount *b;
SavingsAccount s(1, 1000, 0.05);
b = &s;
b->displayBalance();
return 0;
}
int main() {
float x, y;
cin >> x >> y;
try {
float area = CalculateArea(x, y);
cout << area << endl;
} catch (const char* msg) {
cout << msg << endl;
}
return 0;