Originally Posted by
DougDbug
Perfect! You can make an employee class with member variables like FirstName, LastName, Title, Salary, etc. And, you can have member functions like GetLastName(), IncreaseSalary(), etc. The object-name might be an employee number.
But, take it one step at a time... You'll probably want to learn more about the basics, including functions and reading/writing to the disk before you start working on an object oriented "database".
I am already familiar with functions and variables and the other basics similiar to an event driven language, its the object oriented stuff that is new. struct - class ... Here is where I am so far in my latest learning tool...
Code:
// Hello World! V 5_00_00
// struct and class
// by SRS & the assistance of the
// fine people at cprogramming.com
* --------------------------------------------------------------------INCLUDE*/
#include <iostream> // cin/cout
//#include<iomanip>
//#include<fstream>
#include <string> // string
#include <cctype> // tolower
using namespace std;
/* ---------------------------------------------------------------------STRUCT*/
struct contacts
{
string firstName;
string lastName;
string companyName;
string homeAddress;
int id_number;
int age;
};
/* --------------------------------------------------------------------DECLARE*/
void add_someone(); // required to compile
/* ------------------------------------------------------------------FUNCTIONS*/
int yes_no() // Return 1(yes) or 2(no) or re-enter invalid answers
{
char yn;
for(;;)
{
cout << "Please enter \"Y\" or \"N\"" << endl;
string verify;
getline(cin, verify);
int verifySize = verify.size();
if((verifySize <= 0) || (verifySize >= 2)) // next line:
// User enters other than single character reply, re-enter
{
cout << "ERROR: YOUR ANSWER IS INVALID..." << endl;
cout << "Please try again..." << endl;
continue;
}
else // User enters a single character reply
{
yn = verify[0]; // Should not be necessary
yn = tolower(yn); // Force lower input
if(yn == 'y') // User enters Y or y only
{
return 1;
break;
}
else if(yn == 'n') // User enters N or n only
{
return 0;
break;
}
else // User enters any other reply, re-enter
{
cout << "ERROR: YOUR ANSWER IS INVALID..." << endl;
cout << "Please try again..." << endl;
continue;
}
}
}
}
void get_name() // Get & Verify the first and last name, offer repeat
{
string fullName;
for(;;)
{
contacts person;
cout << "Please Enter Your First Name:" << endl;
getline(cin, person.firstName);
cout << "Please Enter Your Last Name:" << endl;
getline(cin, person.lastName);
fullName = person.firstName + " " + person.lastName;
cout << "Please verify your name is correct: " << fullName << endl;
int reply = yes_no();
if(reply)
{
cout << "Hello World, from " << fullName << "!!"<< endl;
break; // Exit the loop upon verification
}
else
{
cout << "Please try again:\n" << endl;
continue; // Repeat the loop for any other answer
}
}
add_someone();
}
void add_someone() // Add a user or exit program
{
cout << "Do you wish to add a new contact now?" << endl;
int reply = yes_no();
if(reply)
{
get_name();
}
else
{
cout << "Very well, have a nice day!" << endl;
}
}
/* -----------------------------------------------------------------------MAIN*/
int main()
{
add_someone();
system ("PAUSE");
}
PLEASE ANYONE/EVERYONE with any suggestions, ideas, alternatives, improvements, post it... my feelings will not be hurt, I am eager to learn and willing to do what ever it takes...
THANK YOU ALL who have helped me learn so far, your time is GREATLY appreciated!