Description class account private std: string account code. std-string first nam
ID: 3777956 • Letter: D
Question
Description class account private std: string account code. std-string first name. std: string last name: double balance. Public This class should have a construetor that initializes ALL members in the initialization list with data passed in as arguments to the constructor as well as accessors for all members 2) Write an application that populates a std: caccount The application will use a std:ifstream vector opened on the file, "account dat which will be supplied to you. If the file cannot be opened, throw an exception 3) The application will then read account information from the file in the following format account code: 10 characters first name: 15 characters last name: 25 characters balance: 8 digits, decimal place, 2 digits For each set of data read, the application should use that data to construct an account object and back that object onto the vector. Each set of data is separated by a newline, which must be skipped between data sets. Trim spaces from the right of the first name and last name fields upon input using the trim right function provided. 4) Use std: sort to sort the std: vector on account number. 5) The application will then create a std:ofstream object and output the vector of accounts to afile, "report tot". Use any format you wish, but make sure to include all members on the output. At the bottom of the report, include the sum of all account balances. 6) THEN... use std:sort to sort the std:vector on balance and output to the console (std:cou) the accounts in this order to see who our largest account holders are. 7) Be sure to use proper exception handling at all stagesExplanation / Answer
Answer for Question 1:
#include <iostream>
using namespace std;
class Account{
private:
char account_code[10];
char first_code[15];
char last_name[25];
double balance;
public:
Account(char ac[], char fc[], char ln[], double b){
cout<<"object is created"<<endl;
for(int i=0;i<10;i++){
account_code[i]=ac[i];
}
for(int i=0;i<15;i++){
first_code[i]=ac[i];
}
for(int i=0;i<25;i++){
last_name[i]=ac[i];
}
balance=b;
};
};
int main()
{
char ac[]="xxxxx";
char fc[]="hello";
char ln[]="world";
double balance=123456.00;
Account a(ac,fc,ln,balance);
return 0;
}
*A class Account is declared to accept Strings
*The above program is accepting a series of characters as strings but if you really want to use the string object then you can inlude string library in the beginning and convert char declarations to string declarations. Here goes the string program
#include <iostream>
#include <string>
using namespace std;
class Account{
private:
string account_code;
string first_code;
string last_name;
double balance;
public:
Account(string ac, string fc, string ln, double b){
cout<<"object is created"<<endl;
balance=b;
};
};
int main()
{
string ac="xxxxx";
string fc="hello";
string ln="world";
double balance=123456.00;
Account a(ac,fc,ln,balance);
return 0;
}
*The account_code, first_code and last_name are generated with 10,15 and 25 length respectively.
*A constructor named Account is also declared. It is called as a parameterized constructor since it accepts parameters.
*Make sure you send the same parameters in the same order when you initialize the constructor.
*A 'cout' statement is written inside the constructor initialization just for testing to make sure that the constructor is initialized. Please remove it after the final program is written.