User defined Class elements and their manipulation

  c++

i am needing to create a class with elements for a savings account, i have to ask the user for account type, name, ID, balance, and closure percentage. I then have to display what was just inputted, and then at the end call an imbedded class function to calculate the closure percentage via the inputted percentage and the balance. Then return that value to the main function and output the answer.

My issues: When i display the users input in the second function it gives me a bunch of long numbers or nothing at all (name). So how can i set the output to clean these up. Am i returning the wrong type? Any help would be greatly appreciated. Thank you, i am new to C++.

Also the layout and return types were defined in the parameters i was given for this task. GetInitalValues and DisplayValues must have a void parameter list and return void, and CalculatePenalty must have a void parameter list and return an appropriate type. And DisplayValues also has to be a constant inline member function.

MAIN CODE:

#include <iostream>
#include <iomanip>
#include "C1A8E1_SavingsAccount.h"
using namespace std;

void GetInitialValues(void);
const inline void DisplayValues(void);

int main()
{
    SavingsAccount MyAccount;

    GetInitialValues();
    DisplayValues();

    cout << "nAccount Closure Penalty: " << MyAccount.CalculatePenalty()
        << "n";

    return 0;
}

Header File:

#include <iostream>
#ifndef C1A8E1_SAVINGSACCOUNT_H // Header Guard
#define C1A8E1_SAVINGSACCOUNT_H
using namespace std;

void GetInitialValues(void);
const inline void DisplayValues(void);

//Class definition 
class SavingsAccount
{
public:
    int type;
    string ownerName;
    long IDnbr;
    double balance, closurePenaltyPercent;

    double CalculatePenalty(void)
    {
        return closurePenaltyPercent * balance;
    }
};

// Define inline function that displays users inputs

// This is where i am supposed to put this function "Outside the Class 
// Definintion above" and where im having the issues
const inline void DisplayValues(void)
{
    SavingsAccount SA;
    cout << "nAccount type: " << SA.type << "nOwner Name: " << SA.ownerName
        << "nID Number: " << SA.IDnbr << "nAccount balance: " << SA.balance
        << "nAccount closure penalty percent: " << SA.closurePenaltyPercent;

    return void();
}
#endif

USER INPUT FUNCTION:

#include <iostream>
#include <string>
#include "C1A8E1_SavingsAccount.h"
using namespace std;

void GetInitialValues(void)
{
    SavingsAccount AccountType, Name, ID, Balance, CP_percent;
    
    cout << "Please Enter Account Type: ";
    cin >> AccountType.type;
    cout << "Enter Name: ";
    cin >> ws;
    getline(cin, Name.ownerName);
    cout << "Enter ID Number: ";
    cin >> ID.IDnbr;
    cout << "Enter Balance: ";
    cin >> Balance.balance;
    cout << "Enter Closure Penalty Percent: ";
    cin >> CP_percent.closurePenaltyPercent;

    return void();
}

Source: Windows Questions C++

LEAVE A COMMENT