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

Create two structures and name the types Account and Money. The Money struct has

ID: 3877496 • Letter: C

Question

Create two structures and name the types Account and Money. The Money struct has two variables One represents how many dollars you have The other represents h ow many cents you have .The Account struct has three variables - A Money struct that will represent how much money is in the account One variable to represent the interest rate as a decimal value. The final variable will contain the name of the account. (Checking. Savings, CD, etc.) Negative amounts of Money are stored by making both variables of the Money object negative * Use the following function prototypes - Account createAccount () * The function shall prompt the user for an account name, interest rate, and starting balance in that order * The prompts shall appear as follows: Let's set up your account First, what' s the name of the account? What is the interest rate of your [NAME] account? Finally, what is the starting balance of your [NAME] account? $ · [NAME] shall be replaced with the name of the account * You may NOT assume that the name of the account contains only a single word * You may assume the user will always type an interest rate as a decimal value (e.g., 0.05) * You may also assume that a positive and valid (whole number or no more than two decimal places) amount of money will be entered - Account deposit (Account account, Money deposit) * The function shall not accept negative amounts of money . If a negative amount of money is attempted to be deposited, an error message will be displayed, and the original account will be returned

Explanation / Answer

C++ Structure and Function
#include <iostream>
using namespace std;

struct Person
{
    char name[50];
    int age;
    float salary;
};

void displayData(Person);   // Function declaration

int main()
{
    Person p;

    cout << "Enter Full name: ";
    cin.get(p.name, 50);
    cout << "Enter age: ";
    cin >> p.age;
    cout << "Enter salary: ";
    cin >> p.salary;

    // Function call with structure variable as an argument
    displayData(p);

    return 0;
}

void displayData(Person p)
{
    cout << " Displaying Information." << endl;
    cout << "Name: " << p.name << endl;
    cout <<"Age: " << p.age << endl;
    cout << "Salary: " << p.salary;
}

Output
Enter Full name: Bill Jobs
Enter age: 55
Enter salary: 34233.4

Displaying Information.
Name: Bill Jobs
Age: 55
Salary: 34233.4

....

In this program, client is requested to enter the name, age and pay of a Person inside fundamental() work.

At that point, the structure variable p is to go to a capacity utilizing.

displayData(p);

The arrival kind of displayData() is void and a solitary contention of sort structure Person is passed.

At that point the individuals from structure p is shown from this capacity.

Case 2: Returning structure from work in C++

...

#include <iostream>
using namespace std;

struct Person {
    char name[50];
    int age;
    float salary;
};

Person getData(Person);
void displayData(Person);

int main()
{

    Person p;

    p = getData(p);  
    displayData(p);

    return 0;
}

Person getData(Person p) {

    cout << "Enter Full name: ";
    cin.get(p.name, 50);

    cout << "Enter age: ";
    cin >> p.age;

    cout << "Enter salary: ";
    cin >> p.salary;

    return p;
}

void displayData(Person p)
{
    cout << " Displaying Information." << endl;
    cout << "Name: " << p.name << endl;
    cout <<"Age: " << p.age << endl;
    cout << "Salary: " << p.salary;
}

..

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