I've done this C++ data structures program is mostly correct, however I am having trouble with the RefFunction()
parameters. They are not designed quite properly. They are not supposed to be pass by value, but rather pass by reference and I'm not sure how to do that. It takes a reference to an int
, and a reference to a double
. It queries the user to input values to be stored in the variables referenced by its arguments. Then be able to return in the class instance and print the values in main()
. I greatly appreciate any help as I am very stuck. Thank you very much.
Header file:
#ifndef Prog1Class_h
#define Prog1Class_h
//A data structure of type Prog1Struct containing three variables
struct Prog1Struct
{
int m_iVal;
double m_dVal;
char m_sLine[81];
};
// A class, Prog1Class, containing a constructor and destructor
// and function prototypes
class Prog1Class
{
public:
Prog1Class();
~Prog1Class();
void PtrFunction(int *, double *);
void RefFunction(int, double);
void StructFunction(Prog1Struct *);
};
#endif
.CPP file
#include "Prog1Class.h"
#include <string>
#include <iostream>
using namespace std;
Prog1Class::Prog1Class() {}
Prog1Class::~Prog1Class() {}
// PtrFunction shall query the user to input values to be stored in the
// variables referenced by it's pointer arguments
void Prog1Class::PtrFunction(int *a, double *b)
{
cout << "Input keyboard values of type integer and double"<<endl;
cin>>*a >>*b;
}
// RefFunction shall be a C++ Reference function and shall query the user to
// input values to be stored in the variables referenced by it's arguments
void Prog1Class::RefFunction(int a, double b)
{
cout << "Input keyboard values of type integer and double"<<endl;
cin >>a >>b;
}
// StructFunction shall query the user to input values to be stored in the
// three fields of the data structure referenced by its argument
void Prog1Class::StructFunction(Prog1Struct* s)
{
cout << "Input keyboard values of type integer and double"<<endl;
cin >>s->m_iVal>>s->m_dVal;
cout <<"Input a character string";
cin.ignore(1000, '\n');
cin.getline(s->m_sLine, 81, '\n');
}