Hello folks,
I am working on an assignment for school and I would greatly appreciate some help with my code. I would like to retrieve some data from my header via a function in my main. However, when I call the function in my main the text shows up, but not the data. If I attempt to retrieve the data straight in the main without the use of a function, I get the right results, it is when I use a function that I have the problem.
Some help would be greatly appreciate it.
here is my header:
Code:
#ifndef HEADER_H
#define HEADER_H
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
class Account
{
public:
char first_name[20];
char last_name[20];
float sin_number;
char account_type[10];
int number_of_transactions;
void set_data(char fname[20],char lname[20],float sinnum, int acctype, int numtrans)
{
strcpy (first_name,fname);
strcpy (last_name,lname);
sin_number = sinnum;
if (acctype = 1)
{
strcpy(account_type, "Chequing");
}
if (acctype = 2)
{
strcpy(account_type,"Savings");
}
number_of_transactions = numtrans;
}
void get_data()
{
cout<<"the first name is : "<<first_name<<endl;
cout<<"the last name is : "<<last_name<<endl;
cout<<"the sin number is : "<<sin_number<<endl;
cout<<"the account type is : "<<account_type<<endl;
cout<<"the number of transactions is : "<<number_of_transactions<<endl;
}
};
#endif
and here is my main:
Code:
#include <iostream>
#include "Account.h"
using namespace std;
class functions : public Account
{
public:
void PrintStatement(void)
{
Account acc;
acc.get_data();
}
int main()
{
Account acc;
functions func;
char fname[20];
char lname[20];
float sinnum;
int acctype;
int numtrans;
cout<<"Please enter the client's first name"<<endl;
cin>>fname;
cout<<"Please enter the client's last name"<<endl;
cin>>lname;
cout<<"Please enter the client's sin number"<<endl;
cin>> sinnum;
cout<<"Please enter the 1: for chequing or 2: for savings"<<endl;
cin>>acctype;
if (acctype !=1 && acctype !=2)
{
cout<<"Invalid account type, Please enter the 1: for chequing or 2: for savings"<<endl;
cin>>acctype;
}
cout<<"Please enter the client's transaction number"<<endl;
cin>>numtrans;
acc.set_data(fname, lname, sinnum, acctype, numtrans);
acc.get_data(); //it works here
func.PrintStatement(); //here it doesnt work
return (0);
}
Thank you very much for your help. I am very new to this.