OOPs Assignment 5 Mayuri
OOPs Assignment 5 Mayuri
(230203)
[Assignment 5]
Submitted to: - Proff. Sanjeev Sharma sir
#include <fstream>
#include <iostream>
#include <string>
int main() {
fstream my_file;
my_file.open("Mayuri.txt");
if (!my_file) {
cout << "No such file";
} else {
string line;
while (1) {
getline(my_file, line);
if (!my_file)
break;
Output
class Account {
public:
Account() {
statement_file.open("Account.txt");
statement_file.seekg(0, ios::end);
if (statement_file.tellg() == 0) {
statement_file.seekg(0, ios::beg);
balance = 1200;
Name = "Mayuri";
account_number = 20;
write();
} else {
get_info();
}
}
~Account() { statement_file.close(); }
void write() {
statement_file.close();
statement_file.open("Account.txt", std::fstream::out | std::fstr
eam::trunc);
statement_file.seekg(0, ios::beg);
statement_file << account_number << "\n" << Name << "\n" << bala
nce;
}
void get_info() {
string line;
statement_file.seekg(0, ios::beg);
getline(statement_file, line);
account_number = stoi(line);
getline(statement_file, line);
Name = line;
getline(statement_file, line);
balance = stod(line);
}
void display() {
std::cout << "\nName : " << Name << "\n"
<< "Account Number : " << account_number
<< "\nBalance : " << balance << std::endl;
}
private:
int account_number;
string Name;
double balance;
fstream statement_file;
};
int main() {
Account One;
int choice;
double data;
switch (choice) {
case 1:
One.display();
break;
case 2:
cout << "\nEnter Ammount to deposit : ";
cin >> data;
One.deposit(data);
break;
case 3:
cout << "\nEnter Ammount to withdraw : ";
cin >> data;
One.withdraw(data);
break;
default:
return 0;
}
}
}
Output
2.we can not create own ios functions while we can create our own
manipulators.