editing attributes from my header files in a program

Hey guys, thank you up front for taking the time to look at this thread.
My question is this,

I have written and compiled three header files that all have attributes like this:

String number; // Patient's medical record number
String firstName; // Patient's first name
char middleInitial; // Patient's middle initial
String lastName; // Patient's last name

also I have created this function in my header file as well
String customheader::getName( )
{
return firstName + " " + middleInitial + " " + lastName;
}


and also a constructor that uses all of those attributes.

When i have the constructor in my cpp filled out with all of the information it clean compiles and executes. However I want to change the program to use cin to input this information...

to clarify: I want to use String firstName(which is initialized in my header file) as a cin inside my program.

Ex:
#include "customheader.h"
#include <iostream.h>

int main()
{
cout << "Please enter your first name." << endl;
cin >> firstName;
cout << "Please enter your middle initial." << endl;
cin >> middleInitial;
cout << "Please enter your last name." << endl;
cin << lastName;

customheader::getName( );

return 0;
}
and have getName use the new information and not the predefined constructor inside of the program. I have looked far and wide and cannot seem to locate the answer.. Any help would be greatly appreciated.
Why would you want to do that? Also, you seem to have "class" and "header" confused; they are very, very different and unrelated.
Well I need for the user to be able to input their own information, instead of me or another programmer having to edit the program to put in a different constructor for every user entered. Everything up until the Ex: part is in my header file, the rest is in a seperate cpp.
Last edited on
What I mean is, why would you need to do anything different? You have a constructor that takes the strings, and you input the strings, can't you just use the constructor and give it the strings you just inputted to?
well that is the thing, I do not have input. My previous program just had the constructor with preset values. In the new program i need to be able to put new values in and still be able to use the functions implemented in my header files. I am not sure how to do this.
Well, an exact copy and paste of your program with some slight modifications:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "customheader.h"
#include <iostream.h>
using namespace std;

int main()
{
    std::string firstName, lastName;
    char middleInitial;
    cout << "Please enter your first name." << endl;
    cin >> firstName;
    cout << "Please enter your middle initial." << endl;
    cin >> middleInitial;
    cout << "Please enter your last name." << endl;
    cin >> lastName;

    customheader A_Patient (firstName, middleInitial, lastName);

    cout << A_Patient.getName() << endl;
}


Also why would your class be called customheader? Why not Patient?
It is actually PatientDemographicInformation, i changed it to customheader to try and show off exactly what areas I was talking about.
when i copied that code in line for line I received over 100 errors, is their not an easier way to just cin information and have it stick to my constructor in the program or the class in my header?
[code] "Please use code tags" [/code]

1
2
3
4
String number; // Patient's medical record number
String firstName; // Patient's first name
char middleInitial; // Patient's middle initial
String lastName;	// Patient's last name 
¿Are those globals, or inside a class?

customheader::getName( ); ¿customheader is a namespace? ¿or getName is an static method?
Neither make sense.

Show your "constructor"
Last edited on
PatientDemographicInformation XInfo(patientMedicalRecordNo, patientFirstName , patientMiddleInitial,
patientLastName, patientStreetAddress1,patientStreetAddress2, patientCity,
patientState, patientZip5, patientZip4, patientHomeAreaCode, patientHomePhoneNo,
patientGender, patientDateOfBirth);
any ideas?
Topic archived. No new replies allowed.