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

Bookmark In this program the user will enter transaction information for their c

ID: 3573150 • Letter: B

Question

Bookmark

In this program the user will enter transaction information for their checking account.
   For each transaction, they will enter:

   Type (C=Check, D=Deposit, W=Withdrawl)
   Amount

   The Amount entered by the user should always be a positive amount, even if its effect on
   the balance is negative (like a Check for $123).

   The information that the user enters must be stored in parallel arrays (one for the transaction
   type and another for the amount). The user is in control of how many transactions to enter
   (up to the maximum number as defined by the MAX_NUMBER_OF_TRANSACTIONS constant).

   After the user is done entering transactions, the program will produce a chart listing the
   transactions. Additionally, an ending balance will be calculated and displayed (assume the
   beginning balance was $0).

   To complete this exam, follow the TODO steps listed below. Remember that each part of this exam
   is worth points, so be sure to complete everything that you know how to do as quickly as you can.
   Also, as always, to get a perfect score it is necessary to write a program that matches the
   Sample Output (shown at the bottom) using the proper techniques taught in this course.

*/

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
   const int MAX_NUMBER_OF_TRANSACTIONS = 6;

   /* TODO - Step 1
   Declare 2 arrays, with data types and names listed below - each
   holding as many values as determined by the constant declared above:

   - array of char, named transactionTypes
   - array of double, named transactionAmounts
   */

   // Parallel array declarations


   // Additional variables
   int index = 0;           // used while entering transactions, keeps track of current array position within the loop
   char again;               // loop control variable, holds 'Y' if user wants to add another transaction

   /* TODO - Step 2
   Complete the DO...WHILE loop that has been started here. You will need to scroll down to where the following line
   is commented out:

   //} while (expression)

   Uncomment the line and change "expression" so the loop repeats if:
       - the user indicated they want to add another transaction, AND
       - fewer than MAX_NUMBER_OF_TRANSACTIONS have been added
   */

   do
   {
       /* TODO - Step 3
       - Prompt the user for the transaction type
       - Read the user's answer and store to the correct array in the correct location
       - Convert the answer the user gave to uppercase and store the result back to the same array location
       */


       /* TODO - Step 4
       Write a WHILE loop to validate the user's entry. If the user's entry was not a C, not a D, and
       not a W:
       - Display the error message
       - Read the user's answer again and store to the correct array in the same location
       - Convert the new answer the user gave to uppercase and store the result back to the same array location
       */


       /* TODO - Step 5
       - Prompt the user for the transaction amount
       - Read the user's answer and store to the correct array in the correct location
       */

      
       /* TODO - Step 6
       Write a WHILE loop to validate the user's entry. If the user's entry was less than or equal to 0:
       - Display the error message
       - Read the user's answer again and store to the correct array in the same location
       */


       /* TODO - Step 7
       Increment the array index variable, readying it for the next time around the loop
       */


       /* TODO - Step 8
       If the parallel array index is still less than the max number of transactions allowed
       (as identified by the MAX_NUMBER_OF_TRANSACTIONS constant), then:
       - as the user if they want to enter another transaction
       - read the user's answer from the keyboard into the variable provided for this purpose
       - convert the user's answer to lowercase and store it back to the loop control variable (again)
       */


       cout << endl;

   //} while (expression)
   // END OF THE DO...WHILE LOOP
   // This is the spot that Step 2 told you to look for and change

   int i;                   // the for loop control variable
   double balance = 0;       // an accumulator to sum the balance based on the transactions
   double amount;           // a temporary variable to hold a transaction's amount

   // Display the header for the transaction ledger
   cout << "T Amount" << endl;
   cout << "- --------" << endl;

   cout << fixed << setprecision(2);

   /* TODO - Step 9
   Write a for loop that will loop based on the number of transaction entered above.
   */

   //for (initialize; test; increment)
   {
       /* TODO - Step 10
       Output the transaction type as the first character on the line, within a two
       character column (setw...)
       */


       /* TODO - Step 11
       If the transaction is one that subtracts from the balance (a Check or Withdrawal)
           store the negative of the transactionAmount to the amount variable
       Otherwise
           store the transactionAmount (without changing it) to the amount variable
       */


       /* TODO - Step 12
       Output the amount within an eight character column (use setw...)
       */


       /* TODO - Step 13
       Properly update the balance using the amount value
       */

   }

   cout << "==========" << endl << endl;

   /* TODO - Step 14
   Output the line that displays the ending balance
   */


   return 0;
}

/* Sample Output

Enter the transaction type (D=Deposit, C=Check, W=Withdrawl): y
ERROR: Transaction type must be D, C, or W - Enter again: D
Enter the transaction amount: 500
Enter another transaction (y/n): y

Enter the transaction type (D=Deposit, C=Check, W=Withdrawl): C
Enter the transaction amount: 123.45
Enter another transaction (y/n): y

Enter the transaction type (D=Deposit, C=Check, W=Withdrawl): W
Enter the transaction amount: -200
ERROR: Transaction amount must be greater than 0 - Enter again: 200
Enter another transaction (y/n): y

Enter the transaction type (D=Deposit, C=Check, W=Withdrawl): d
Enter the transaction amount: 893.20
Enter another transaction (y/n): y

Enter the transaction type (D=Deposit, C=Check, W=Withdrawl): w
Enter the transaction amount: 250
Enter another transaction (y/n): y

Enter the transaction type (D=Deposit, C=Check, W=Withdrawl): c
Enter the transaction amount: 444.44

T Amount
- --------
D 500.00
C -123.45
W -200.00
D 893.20
W -250.00
C -444.44
==========

Ending Balance = $375.31
Press any key to continue . . .

Explanation / Answer

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
const int MAX_NUMBER_OF_TRANSACTIONS = 6;

/* TODO - Step 1
Declare 2 arrays, with data types and names listed below - each
holding as many values as determined by the constant declared above:

- array of char, named transactionTypes
- array of double, named transactionAmounts
*/

// Parallel array declarations

// Additional variables
char transType[6];
double transAmount[6];
int index = 0; // used while entering transactions, keeps track of current array position within the loop
char again; // loop control variable, holds 'Y' if user wants to add another transaction

/* TODO - Step 2
Complete the DO...WHILE loop that has been started here. You will need to scroll down to where the following line
is commented out:*/

//Uncomment the line and change "expression" so the loop repeats if:
// - the user indicated they want to add another transaction, AND
// - fewer than MAX_NUMBER_OF_TRANSACTIONS have been added

do
{
// TODO - Step 3
cout<<"Enter the Transaction Type(C,D or W):";//- Prompt the user for the transaction type
cin>>transType[index]; //Read the user's answer and store to the correct array in the correct location
toupper(transType[index]);//- Convert the answer the user gave to uppercase
   //transType[index]=type;// and store the result back to the same array location

///TODO - Step 4
while(transType[index]!='c'&& transType[index]!='d'&& transType[index]!='w')//Write a WHILE loop to validate the user's entry. If the user's entry was not a C, not a D, and not a W:
{
       cout<<"Error in the Transation Type u entered: ";// Display the error message
cout<<"Enter the Transaction Type(C,D or W):";//- Prompt the user for the transaction type
cin>>transType[index];// Read the user's answer again and store to the correct array in the same location
toupper(transType[index]); //- Convert the new answer the user gave to uppercase and store the result back to the same array location
}

// TODO - Step 5
cout<<"Enter the Transation Amount: ";//- Prompt the user for the transaction amount
cin>>transAmount[index];//- Read the user's answer and store to the correct array in the correct location

  
// TODO - Step 6
//Write a WHILE loop to validate the user's entry. If the user's entry was less than or equal to 0:
while(transAmount[index]<=0 ) //Display the error message
{
       cout<<"enter positive value: ";
       cout<<"Enter the Transation Amount: ";//- Prompt the user for the transaction amount
cin>>transAmount[index];//cRead the user's answer again and store to the correct array in the same location
}

// TODO - Step 7
index++;//Increment the array index variable, readying it for the next time around the loop

// TODO - Step 8
if(index<6)//If the parallel array index is still less than the max number of transactions allowed(as identified by the MAX_NUMBER_OF_TRANSACTIONS constant), then:
{
   cout<<"Do u wnt to perform another transaction(Y/N)?";//- as the user if they want to enter another transaction
cin>>again;//- read the user's answer from the keyboard into the variable provided for this purpose
tolower(again);//- convert the user's answer to lowercase and store it back to the loop control variable (again)
}

cout << endl;

} while (again=='y' && index<6);
// END OF THE DO...WHILE LOOP
// This is the spot that Step 2 told you to look for and change

int i; // the for loop control variable
double balance = 0; // an accumulator to sum the balance based on the transactions
double amount=0.0; // a temporary variable to hold a transaction's amount

// Display the header for the transaction ledger
cout << "T Amount" << endl;
cout << "- --------" << endl;

cout << fixed << setprecision(2);

/* TODO - Step 9
Write a for loop that will loop based on the number of transaction entered above.
*/

for (i=0;i<index; i++)
{
//TODO - Step 10
cout<<(char)toupper(transType[i])<<setw(4);//Output the transaction type as the first character on the line, within a two character column (setw...)
//TODO - Step 11
if(transType[i]=='c' ||transType[i]=='w')
   //If the transaction is one that subtracts from the balance (a Check or Withdrawal)
       transAmount[i]=-1*transAmount[i];//store the negative of the transactionAmount to the amount variable Otherwise store the transactionAmount (without changing it) to the amount variable

// TODO - Step 12
cout<<transAmount[i]<<setprecision(2)<<endl;//Output the amount within an eight character column (use setw...)

//TODO - Step 13
amount=amount+transAmount[i];//Properly update the balance using the amount value

}
cout << "==========" << endl << endl;

//TODO - Step 14
cout<<"Ending Balance is "<<amount;//Output the line that displays the ending balance

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