Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to write a program in c++ which is going to use inheritance. It should s

ID: 3756200 • Letter: Y

Question

You are to write a program in c++ which is going to use inheritance. It should start off with the base classes

Account: contains the string name, int accountnumber, double balance.

Savings: Derived from Account class, it should contain double interest rate.

Checkings: Derived from Account class, it should contain double overdraftlimit.

CreditCard: Derived from Checkings class, it should contain int cardnumber.  

Create a program which will create an array of 3 Savings accounts, 3 Checkings accounts and 3 CreditCards.

Create 3 files. Savings.txt, Checkings.txt, CreditCards.txt which contains the information for each and infile the information from the file to the array of the classes.

You will be graded on the method used to infile (make sure to use loops), the way the classes are constructed (inheritance), and the way the the classes are used (make sure the constructor and overloaded constructor is used correctly).

As for the Main, simply get all the data from the files in to the objects correctly and do a display of all 3 savings, checkings and creditcards in a neat fashion (iomanip).

zip the whole project and upload it (make sure the files are already populated with data).

Explanation / Answer

Create 3 files named: Savings.txt

                                Checkings.txt

                                CreditCards.txt

in the respective folder according to your compiler. I have used turbo c++ compiler. So, the these files are created in the folder location of C:TURBOC3BIN

The below code has the code to input data into these text files. It is optional for you to use that after the data is written to the text files. I have placed it in multiple comments(/*    */). For once run it without comments, after that run with the comments or you can remove the code within it and the comments.

#include<iostream.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
#include<conio.h>


class Account
{
public:
char name[20];
int accountnumber;
double balance;

Account()        //Constructor
{
   strcpy(name," ");
   accountnumber=0;
   balance=0.0;
}

Account(char name[20], int accountnumber, double balance) //constructor
{
   strcpy(this->name,name);
   this->accountnumber=accountnumber;
   this->balance=balance;
}

void display_Account()   //To display Account details
{
   cout<<"Name is: ";
   puts(name);
   cout<<"Account Number is: "<<accountnumber<<endl;
   cout<<"Balance is: "<<balance<<endl;
}

void get_Account() //Function to get Account details
   {
   cout<<"Enter Name: ";
   gets(name);
   cout<<"Enter Account Number: ";
   cin>>accountnumber;
   cout<<"Enter Balance: ";
   cin>>balance;
   }

};

class Savings : public Account
{
   public:
   double interest_rate;

   Savings()        //constructor
   {
       interest_rate=0;
   }

   Savings(double interest_rate)     //constructor
   {
       this->interest_rate=interest_rate;
   }

   void get_Savings()     //Function to get Savings details
   {
       get_Account();
       cout<<"Enter interest rate: ";
       cin>>interest_rate;
   }

   void display_Savings() //Functiom to display Savings details
   {
       display_Account();
       cout<<"Interest Rate is: "<<interest_rate<<endl;
   }
};

class Checkings : public Account
{
   public:
    double overdraftlimit;

   Checkings() //Constructor
   {
       overdraftlimit=0;
   }

   Checkings(double overdraftlimit) //Constructor
   {
       this->overdraftlimit=overdraftlimit;
   }

   void get_Checkings() //Function to get Checking details
   {
       cout<<"Enter Overdraft limit: ";
       cin>>overdraftlimit;
   }

   void display_Checkings() //Function to display Checking details
   {
       cout<<"Overdraft limit is: "<<overdraftlimit<<endl;
   }
};

class CreditCard : public Checkings
{
   public:
   int cardnumber;

   CreditCard()    //Constructor
   {
       cardnumber=0;
   }

   CreditCard(int cardnumber) //Constructor
   {
       this->cardnumber=cardnumber;
   }

   void get_CreditCard() //Function to get Checking details
   {
       cout<<"Enter Credit card number: ";
       cin>>cardnumber;
   }

   void display_CreditCard() //Function to display Checking details
   {
       cout<<"Credit card number is: "<<cardnumber<<endl;
   }

};

int main()
{
   clrscr();
   int i;
   Savings a[3];
   Checkings b[3];
   CreditCard c[3];

   fstream file1,file2,file3;

   file1.open("Savings.txt",ios::in,ios::out);

   if(!file1)
   {
       cout<<"Cannot open file"<<endl;
       return 0;
   }

/* comment 1


   for( i=0;i<3;i++)
   {  
       a[i].get_Savings();
       file1.write((char *) &a[i] , sizeof(a[i]));
   }               

*/       

   file1.seekg(0);

   for(i=0;i<3;i++)
   {
        file1.read((char *) &a[i] , sizeof(a[i]));
       a[i].display_Savings();

   }

   file1.close();

   file2.open("Checkings.txt",ios::in,ios::out);

   if(!file2)
   {
       cout<<"Cannot open file"<<endl;
       return 0;
   }

/* comment 2


   for(i=0;i<3;i++)
   {
       b[i].get_Checkings();
       file2.write((char *) &b[i] , sizeof(b[i]));
   }

*/

   file2.seekg(0);

   for(i=0;i<3;i++)
   {
        file2.read((char *) &b[i] , sizeof(b[i]));
       b[i].display_Checkings();

   }

   file2.close();

   file3.open("CreditCards.txt",ios::in,ios::out);

   if(!file3)
   {
       cout<<"Cannot open file"<<endl;
       return 0;
   }

/* comment 3

   for(i=0;i<3;i++)
   {
        c[i].get_CreditCard();
       file3.write((char *) &c[i] , sizeof(c[i]));
   }

*/

   file3.seekg(0);

   for(i=0;i<3;i++)
   {
        file3.read((char *) &c[i] , sizeof(c[i]));
       c[i].display_CreditCard();

   }

   file3.close();

   getch();
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote