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

Please help me with . We have to use structs • Write a C++ program to manage a c

ID: 3909992 • Letter: P

Question

Please help me with . We have to use structs

• Write a C++ program to manage a credit card company with at least one ADT

(Account) with the following members:

card number, customer name, credit limit, and balance.

• The customer can pay the total amount of his/her balance or part of it.

• The customer can make a purchase using the credit card.

• The user can create, modify, and delete accounts.

• All new accounts are created with $300 credit limit.

• Customers’ data is stored in a binary file.

Assignment: Credit Card Company Program Cont’d

• The program’s main menu has the following options:

1. Create a new account

2. Pay balance

3. Make a purchase

4. Check balance

5. Edit an account

6. Close an account

7. View all accounts

8. Exit

Assignment: Credit Card Company Program Cont’d

• Two types of output:

1. Text output printed on the screen.

Messages like “account closed!”.

(Part A of your homework).

2. LED indicators’ lights on a breadboard connected to Raspberry Pi GPIO port.

(Part B of your graded work in the lab)

Assignment: Credit Card Company Program Cont’d

• Text Output (Part A of your homework):

• Create a new account: Print “Account created” on success or “Creation Failed” on

failure (duplicate credit card number)

• Pay balance: Print “Fully paid off” on full payment or “partially paid off” if partial

payment is made.

• Make a purchase: Print “Purchase made” on success or “Purchase Failed” on

failure (purchase amount exceeds the remaining credit limit)

• Check balance: Print “No balance to pay” if balance is 0, “Card maxed out” if

balance = credit limit (credit limit is reached), “Your balance is XXX” otherwise.

• Edit an account: Print “Account modified” on success or “Modification Failed” on

failure (duplicate credit card number)

• Close an account: Print “Account closed” on success or “Closing Failed” on failure

(cannot close an account if balance is not paid off first)

Explanation / Answer

#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
struct account
{
float balance;
float limit;
char name[30];
int no;
struct account *next;
};
struct account *head=NULL;
void create_account(struct account *new1,int ac_no)
{
if(new1!=NULL)
{
  new1->balance=0;
  new1->limit=300;
  new1->no=ac_no;
  cout<<" Enter Name of holder:";
  cin>>new1->name;
  new1->next=head;
  head=new1;
  cout<<" Account created ";
}
else
{
  cout<<" Creation Failed ";
}
}
void purchase(struct account *obj)
{
if(obj)
{
  float amt;
  cout<<" Enter purchase ammount:";
  cin>>amt;
  if((amt+obj->balance)<=obj->limit)
  {
   obj->balance=amt+obj->balance;
   cout<<" Purchase Successful ";
  }
  else
  {
   cout<<" Purchase Failed ";
  }
}
else
{
  cout<<" Purchase Failed ";
}
}
void pay(struct account *obj)
{
if(obj&&obj->balance>0)
{
  float amt;
  cout<<" Enter pay ammount:";
  while(1)
  {
   cin>>amt;
   if(amt<1)
   {
    cout<<" Enter amount greater then 0:";
   }
   else
   {
    break;
   }
  }
  if(obj->balance>=amt&&obj->balance>0)
  {
   if(amt==obj->balance)
   {
    cout<<" Full Payment Successful ";
   }
   else
   {
    cout<<" Partial Payment Successful ";
   }
   obj->balance=obj->balance-amt;
  }
  else
  {
   cout<<" Payment Failed ";
  }
}
else
{
  cout<<" Payment Failed ";
}
}
void balance(struct account *obj)
{
if(obj)
{
  cout<<" You need to pay $"<<obj->balance<<endl;
}
else
{
  cout<<" Account Not Found ";
}
}
void edit_acc(struct account *obj)
{
if(obj)
{
  cout<<" Card Holders Name:"<<obj->name<<endl;
  cout<<" Enter new name:";
  cin>>obj->name;
}
else
{
  cout<<" Account Not Found ";
}
}
struct account *find_account()
{
int num;
struct account *trav=head;
cout<<" Enter account number:";
cin>>num;
while(trav!=NULL)
{
  if(trav->no==num)
  {
   return trav;
  }
  trav=trav->next;
}
return NULL;
}
void view()
{
if(head!=NULL)
{
  struct account *obj=head;
  cout<<" Account Detail ";
  while(obj!=NULL)
  {
   cout<<" ...................."<<obj->name<<"'s Account........................... ";
   cout<<"Account Number:"<<obj->no<<endl;
   cout<<"Account Name:"<<obj->name<<endl;
   cout<<"Account Limit:"<<obj->limit<<endl;
   cout<<"Account Balance:"<<obj->balance<<endl;
   cout<<" ............................................... ";
   obj=obj->next;
  }
}
else
{
  cout<<" No Account Found ";
}
}

void account_delete()
{
struct account *temp;
struct account *trav=head;
int flag=1;
int num;
cout<<" Enter account number:";
cin>>num;

if(trav->no==num&&flag)
{
  temp=head;
  head=head->next;
  free(temp);
  flag=0;
}
while(trav->next!=NULL&&flag)
{
  if(trav->no==num)
  {
   temp=trav->next;
   trav->next=trav->next->next;
   free(temp);
   flag=0;
  }
  trav=trav->next;
}
if(flag)
{
  temp=trav;
  cout<<" check-1 ";
  trav=trav->next;
  cout<<" check-1 ";
  if(trav->no==num)
  {
   cout<<" check-2 ";
   temp->next=NULL;
   free(trav);
   flag=0;
  }
  cout<<" check-3 ";
}
if(!flag)
{
  cout<<" Account Deleted ";
}
else
{
  cout<<" Deletion Failed ";
}
}
int main()
{
int ch=0;
int ac_no=0;
struct account *new1;
while(ch!=8)
{
  cout<<" 1. Create Account.";
  cout<<" 2. Make a Purchase";
  cout<<" 3. Make Payment";
  cout<<" 4. Check Balance.";
  cout<<" 5. Edit an Account.";
  cout<<" 6. Close an Account";
  cout<<" 7. View All Accounts.";
  cout<<" 8. Exit";
  cout<<"    Enter your choice: ";
  while(1)
  {
   cin>>ch;
   if(ch<1||ch>8)
   {
    cout<<" Please Enter valid choice: ";
   }
   else
   {
    break;
   }
  }
  switch(ch)
  {
   case 1:
    new1=(struct account *)malloc(sizeof(struct account));
    ac_no++;
    create_account(new1,ac_no);
    break;
   case 2:
    purchase(find_account());
    break;
   case 3:
    pay(find_account());
    break;
   case 4:
    balance(find_account());
    break;
   case 5:
    edit_acc(find_account());
    break;
   case 6:
    account_delete();
    break;
   case 7:
    view();
    break;
  }
}
cout<<" Exit ";
}