Question

In: Computer Science

Hello all, I am toward the beginning of my semseter and am still pretty rusty working...

Hello all, I am toward the beginning of my semseter and am still pretty rusty working with code. here is my following goal: basically create a structure and populate an array from a txt file which contains

98 45.70
72 15.0
12 0.0
56 43.26
83 123.0
28 931.96
123 12.38

"Create a struct named familyFinance that contains 2 members: ▪ int acctNos ▪ float balance o (prior to the while loop) Create an array financeAry (size 10), of type familyFinance o Populate familyFinance by reading from the file lab3data.txt (each line has an acctNo and balance) o Modify function parameters (for spitThemOut and anyBelowThreshold) so they work with financeAry. Modify as well, the prototypes, and the actual calling/invocation (in while loop). NO change to function names. o (in while loop) If Option 1 chosen, cout “NOT implemented.” and comment the call to printOnesBelowThreshold"

here is what i have for code so far.

#include <iostream>

#include <iomanip>

#include <fstream>

using namespace std;

void printOnesBelowThreshold(float, int [], float [], int);

void spitThemOut(int [], float [], int);

bool anyBelowThreshold(int [], float [], int, float);

struct familyFinance {

    int acctNOS;

    float balance;

};

int main() {

    int acctNos[] = {98, 72, 12, 56, 83, 28, 123};

    float balance[] = {45.70, 15, 0, 43.26, 123, 931.96, 12.38};

    int noAccounts = 7, option;

    float threshold;

    double financeAry [10];

    int x = 0;

    {

    ifstream inFile;

    inFile.open("lab3data.txt");

    while(!File.eof())

    {

        inFile >> financeAry[x].acctNos;

        infile >> balance[x].acctNos

        x++;

   

    }

inFile.close();

    }

    

    while (true) {

        cout << "Option (1 2 3 or other# to quit): ";

        cin >> option;

        switch (option) {

            case 1:

                cout << endl << "Not Implemented: ";

                break;

            case 2:

                spitThemOut(acctNos, balance, noAccounts);

                break;

            case 3:

                cout << endl << "Balance threshold please: ";

                cin >> threshold;

                if (anyBelowThreshold (acctNos, balance, noAccounts, threshold))

                    cout << endl << "Yes, some a/c below balance of :" << threshold;

                break;

            default:

                cout << endl << "All done" << endl;

                exit(1);

        }

    }

}

//Option 1: Dipaly each account and balance, if < Threshold

void printOnesBelowThreshold(float threshold, int acctNos[], float balance[], int upperBound) {

    cout << showpos;

    for (int i = 0; i < upperBound; i++) {

        if (balance[i] < threshold) {

            cout << "Acct, Balance < Threshold: " << setw(3)

                << acctNos [i] << " " << balance[i] << endl;

        }

    }

}

//Option 2: Dipaly each account and balance

void spitThemOut(int acctNos[], float balance[], int upperBound) {

    cout << showpos;

    for (int i = 0; i < upperBound; i++) {

        cout << "Acct, Balance: " << setw(3)

            << acctNos [i] << " " << balance[i] << endl;

    }

}

//Option 3: Return true if any Balance < Threshold

bool anyBelowThreshold (int acctNos[], float balance[], int upperBound, float threshold) {

    for (int i = 0; i < upperBound; i++)

        if (balance[i] < threshold)

            return true;

    return false;

}

Solutions

Expert Solution

#include <iostream>

#include <iomanip>

#include <fstream>

#include <cstdlib> // for exit

using namespace std;

struct familyFinance

{

       int acctNos;

       float balance;

};

// function prototypes

void printOnesBelowThreshold(float, familyFinance [] , int);

void spitThemOut(familyFinance [], int);

bool anyBelowThreshold(familyFinance [], int, float);

int main() {

       int size = 10;

       familyFinance financeAry[size];

       float threshold;

       int noAccounts, option;

       ifstream inFile;

       inFile.open("lab3data.txt");

       if(inFile.is_open()) // if file can be opened

       {

             noAccounts = 0;

             // read till the end of file or till maximum size of array records have been read

             while(!inFile.eof() && (noAccounts < size))

             {

                    inFile >> financeAry[noAccounts].acctNos>>financeAry[noAccounts].balance;

                    noAccounts++;

             }

             inFile.close(); // close the file

            

             while (true) {

                    cout << "Option (1 2 3 or other# to quit): ";

                    cin >> option;

                    switch (option) {

                           case 1:

                                 cout << endl << "Not Implemented: ";

                                 break;

                           case 2:

                                 spitThemOut(financeAry, noAccounts);

                                 break;

                           case 3:

                                 cout << endl << "Balance threshold please: ";

                                 cin >> threshold;

                                 if (anyBelowThreshold (financeAry, noAccounts, threshold))

                                        cout << endl << "Yes, some a/c below balance of :" << threshold<<endl;

                                 break;

                           default:

                                 cout << endl << "All done" << endl;

                                 exit(1);

                    }

             }

       }

       return 0;

}

//Option 1: Display each account and balance, if < Threshold

void printOnesBelowThreshold(float threshold, familyFinance financeAry[], int upperBound) {

    cout << showpos;

    for (int i = 0; i < upperBound; i++) {

        if (financeAry[i].balance < threshold) {

            cout << "Acct, Balance < Threshold: " << setw(3)

                << financeAry[i].acctNos << " " << financeAry [i].balance << endl;

        }

    }

}

//Option 2: Display each account and balance

void spitThemOut(familyFinance financeAry[], int upperBound) {

    cout << showpos;

    for (int i = 0; i < upperBound; i++) {

        cout << "Acct, Balance: " << setw(3)

            << financeAry[i].acctNos << " " << financeAry[i].balance << endl;

    }

}

//Option 3: Return true if any Balance < Threshold

bool anyBelowThreshold (familyFinance financeAry[], int upperBound, float threshold) {

    for (int i = 0; i < upperBound; i++)

        if (financeAry[i].balance < threshold)

            return true;

    return false;

}

//end of program

Output:

Input File:

Output:


Related Solutions

Hello i am working on an assignment for my programming course in JAVA. The following is...
Hello i am working on an assignment for my programming course in JAVA. The following is the assignment: In main, first ask the user for their name, and read the name into a String variable. Then, using their name, ask for a temperature in farenheit, and read that value in. Calculate and print the equivalent celsius, with output something like Bob, your 32 degrees farenheit would be 0 degrees celsius Look up the celsius to farenheit conversion if you do...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on a C-program that deals with memory mapping, Please show all code...
Hello, I am working on a C-program that deals with memory mapping, Please show all code (code must be in the C) and outputs. The instructions are as follows INSTRUCTIONS: You have two sample c codes, one for the client and one for the server. IF the client makes a change in the shared memory, those changes will show on the server side. Your task is to adapt the change strategy to develop two applications so they can send messages...
Hello, I am having difficulty with this assignment. I chose Amazon as my stock, but I...
Hello, I am having difficulty with this assignment. I chose Amazon as my stock, but I am confused on what they're asking :             Choose a stock that interests you. Utilizing Bloomberg (or other financial websites) as a source of data, collect the following      information:                         a. The stock’s Beta                         b. The rate of return on the market (S&P 500 Index)                         c. The risk-free rate (rRF)                         d. The last dividend paid (D0)...
“Hello, I am Lillian Tudor, and I was married to my high school sweetheart, Earl, for...
“Hello, I am Lillian Tudor, and I was married to my high school sweetheart, Earl, for 53 wonderful years. He died 2 years ago and I miss him to this day. Earl and I had three children, two of whom passed before Earl. Our oldest daughter, Leigh, is still helping me around the house and is a blessing to me in my old age. Let me tell you something. Getting old ain’t for sissies! I’m 84 years old as of...
I am working on extensive report for my Advanced Corp. Tax class and I am hoping...
I am working on extensive report for my Advanced Corp. Tax class and I am hoping to get a better understanding of the following: -In order for a corporation to make a valid “S” election, the corporation must be a “small business corporation.” Explain the meaning of “small business corporation” in this context. -Explain what ‘separately stated items’ are in regards to Partnerships and S corporations? Give an example of ‘separately stated items’ for each type of entity. -What requirements...
Hi I am working on my chemistry homework about acids and bases and I am confused...
Hi I am working on my chemistry homework about acids and bases and I am confused on this question from a lab. We used grape juice and cranberry juice and we had to put HCl and NaOH in the test tube full of juice. 1. Referring back to procedure 1 of the experiment, which of the two juices is more useful as a general pH indicator and why? I think it is grape juice but I just don't know what...
Hello, I am wondering what should my Ho and Ha be in this case and what...
Hello, I am wondering what should my Ho and Ha be in this case and what should i do to carry out the test Test whether size is an effective predictor of house prices in the regression model. State your null and alternative hypotheses and report the test statistic, decision rule, and conclusion to the test. [2 marks]
Hello this is for C++ language. I am currently stuck on creating my api for Day...
Hello this is for C++ language. I am currently stuck on creating my api for Day Trading Stocks. as follows I need an api for *//Function Signature * * parameter: * * Return Value: ** *// Write the following function taking in an integer vector (vector &prices) consisting of all prices, in chronological order, for an hypothetical instrument. Your function recommends the maximum profit an investor can make by placing AT MOST one buy and one sell order in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT