Now whats wrong with this thing...
Have this working a little better but, as before, I don't understand why it freezes after the first function call...Help, Please.
Code:
//Class definition for personType
#ifndef PERSON_TYPE_H
#define PERSON_TYPE_H
const int N_S = 20;
const int D_S = 500;
class personType
{
public:
personType();//default constructor
personType(char*, int, char*);//constructor
void setName(char* aName);
int setAge(int anAge);
void setDescription(char* aDescription);
~personType();
private:
char* name;
int age;
char* description;
};
#endif
#include <iostream>
#include "PersonType.h"
using namespace std;
personType::personType()
{
name = NULL;
age = 0;
description = NULL;
}
personType::personType(char* name, int age, char* description)//Constructor with parameters
{
setName(name);
setAge(age);
setDescription(description);
}
void personType::setName(char* aName)
{
char temp[N_S];
cout << "Please enter the person's name." << endl;
cout << ">>>";
for(int i = 0;i < N_S;i++ )
{
cin >> temp[i];
break;
}
for(int j = 0; j < strlen(temp); j++)
{
description[j] = temp[j];
break;
}
cout << endl;
return;
}
int personType::setAge(int anAge)
{
int temp;
cout << "Please enter the person's age." << endl;
cout << ">>>";
cin >> temp;
if(!cin)
{
cin.clear();
cin.ignore(100, '\n');
cout << "Invalid input.";
}
age = temp;
return 0;
}
void personType::setDescription(char* aDescription)
{
char temp[D_S];
cout << "Please type the person's description." << endl;
cout << ">>>";
for(int i = 0;i < D_S;i++)
cin >> temp[i];
for(int j = 0; j < strlen(temp); j++)
description[j] = temp[j];
cout << endl;
return;
}
personType::~personType()
{
delete []name;
delete []description;
}
#include <iostream>
#include "PersonType.h"
using namespace std;
const int L_S = 20;
int main()
{
int i = 0;
char tempN[N_S];
int tempA;
char tempD[D_S];
personType person;
personType personList[L_S];
person.setName(tempN);
person.setAge(tempA);
person.setDescription(tempD);
personList[i] = person;
return 0;
}