Question

In: Computer Science

The attached account info file consists of a triple of information. A valid account number The...

The attached account info file consists of a triple of information.

A valid account number

The current account balance

The maximum account balance

Using the account info file write a program using appropriate functions that lets a user:

Enter a given account number

Enter a charge amount (positive values only)

This program then validates the account number and the amount. Then it determines if the current requested charge will exceed the account balance.

if a valid account, print a validation message

If a valid amount then print if the charge is accepted

if anything is invalid print a message indicating what is wrong.

Store the values in the file in appropriate vectors. once stored in the vectors, use the selection sort method to sort the array and use a binary search method to find the account number.

Do not use the algorithms library for either the sort or search, write the functions yourself.

txt file

5658845 6559.14 7500.00
4520125 1352.83 5000.00
7895122 142.41 5000.00
8777541 4563.07 5000.00
8451277 6160.57 10000.00
1302850 3741.25 10000.00
8080125 2374.01 10000.00
1562555 6549.02 7500.00
5552012 1089.54 10000.00
5050552 491.00 7500.00
7825877 501.83 10000.00
1250255 1427.56 7500.00
1005231 4725.82 5000.00
6545231 9478.78 10000.00
3852085 2211.99 10000.00
7576651 246.55 7500.00
7881200 1335.15 5000.00
4581002 930.58 5000.00

Solutions

Expert Solution

C++ program:

#include <iostream>
#include <fstream>
using namespace std;
int binarySearch(int accNumber,int accNum[],int n)
{
   int first = 0;
   int last = n-1;
   int middle = (first+last)/2;
   while (first <= last)
   {
       if(accNum[middle] < accNumber)
       {
           first = middle + 1;

       }
       else if(accNum[middle] == accNumber)
       {
           return middle;
           break;
       }
       else
       {
           last = middle - 1;
       }
       middle = (first + last)/2;
   }
   if(first > last)
   {
       return -1;
   }
}

int main()
{
   //declare vectors to store data
   int accNum[20];
   double currBalance[20];
   double maxAccBalance[20];
  
   int n=0;
   //opening the file , if it exists
   ifstream infile("info.txt");
   if(!infile)
   {
       cout<<"Please provide input file info.txt";
       exit(0);
   }
   //reading the file info.txt
   while(!infile.eof())
   {
       cin>>accNum[n]>>currBalance[n]>>maxAccBalance[n];
       n++;
   }
  
   //selection sort
int minAccLoc;
for (int i = 0; i < n; i++)
{
minAccLoc = i;

for (int j = i + 1; j < n; j++)
{
if (accNum[j] < accNum[minAccLoc])
{
minAccLoc = j;
}
}

//Swap the values
int temp=accNum[i];
   accNum[i]=accNum[minAccLoc];
   accNum[minAccLoc]=temp;
  
   double t=currBalance[i];
   currBalance[i]=currBalance[minAccLoc];
   currBalance[minAccLoc]=t;
  
   t=maxAccBalance[i];
   maxAccBalance[i]=maxAccBalance[minAccLoc];
   maxAccBalance[minAccLoc]=t;
}  
int accNumber;
double charge;
while(1)
{
   cout<<endl<<"Enter the user account number: ";
   cin>>accNumber;
   int loc=binarySearch(accNumber,accNum,n);
   if(loc==-1)
   cout<<endl<<"Invalid account number";
   else
   {
       cout<<endl<<"Valid account number";
       cout<<"Enter the current requested charge : ";
       cin>>charge;
       if(charge>currBalance[loc])
       cout<<endl<<"Requested charge is not accepted since it exceeds account balance.";
       else
       {
           cout<<endl<<"Requested charge is accepted.";
           currBalance[loc]-=charge;
       }
   }
}
  
}


Related Solutions

Develop a simple MIS (Management Information System) that consists of a simple database (a text file)....
Develop a simple MIS (Management Information System) that consists of a simple database (a text file). The system manages to dynamically input record/data into the database. The data from the database can be sorted, searched and updated. User also should be able to add new records/data, remove any data and etc. Here are some ideas of MIS that can be developed: 1. Hotel reservation system. 2. Students management system. 3. Payroll management system. 4. Bus/Railway/Plane ticketing system. 5. Clinic record...
When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name.
When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name. using name John Smith phone number 1234567893 Using net beans take the first two letters from smith and first 3 numbers from the phone number and combine them to one line like this sm123.
Be able to identify valid and non-valid programmer-defined identifiers. Which header file do you need in...
Be able to identify valid and non-valid programmer-defined identifiers. Which header file do you need in order to use the cout and cin objects? Which header file do you need to create string variables? Be able to recognize the correct syntax to define a constant. Be able to recognize the correct syntax to store a character in a char variable. What must you have for every variable you use in a program? Program Given a program, be able to fill...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
The attached numberpairs.csv file contains lines of comma-separated number pairs, e.g. 2.0,1 5.5,2 10,0 5.1,9.6 Write...
The attached numberpairs.csv file contains lines of comma-separated number pairs, e.g. 2.0,1 5.5,2 10,0 5.1,9.6 Write a program which reads the file using the Python CSV module, creates a list from the contents, then divides the first number in each line by the second. Define a function in your program that performs the division operations; the function must accept two numeric parameters, divide the first parameter by the second, and return the result. Before dividing, your function must validate the...
a) a simple harmonic oscillator consists of a glass bead attached to a spring. it is...
a) a simple harmonic oscillator consists of a glass bead attached to a spring. it is immersed in a liquid where it loses 10% of its energy over 10 periods. compute the coefficient of kinetic friction b assuming spring constant k=1 N/m and mass m=10 grams; b) suppose the spring is now disconnected and the bead starts failing in the liquid, accelerating until it reaches the terminal velocity. compute the terminal velocity.
Assume there is a file which consists of 20 blocks. Consider that the file-control block is...
Assume there is a file which consists of 20 blocks. Consider that the file-control block is already stored in the memory. Calculate the number of disk I/O operations are required for contiguous and linked allocation strategies, if, for one block, the following conditions hold. Also assume that the block information to be added is stored in memory. a. The block is added at the beginning. b. The block is added in the middle. c. The block is added at the...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
List and describe the valid authorization for release of information
List and describe the valid authorization for release of information
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT