473,326 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Need classes help.

This is my header file.

[PHP]#include <string>
using std::string;

class Employee
{
public:
Employee(string,string,int) ;
void setFirstName( string );
string getFirstName();
void setLastName( string );
string getLastName();
void setMonthlySalary(int);
int getMonthlySalary();
private:
string Fname;
string Lname;
int Salary;

};[/PHP]

Below is my body file:

[PHP]#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include "employ.h"


Employee::Employee(string str, string obc, int range )
{

setFirstName(str);
setLastName(obc);
setMonthlySalary(range);
}

void Employee::setFirstName(string str)
{
Fname= str;

cout <<" Employee's first name is:" << str << endl;
}

// string Employee::getFirstName()
// {
// return Fname;
// }




void Employee::setLastName(string obc)
{
Lname= obc;

cout<<" Employee's last name is:" << obc <<endl;
}

//string Employee::getLastName()
//{
// return Lname;
// }

// int Employee::getMonthlySalary()
// {
// return Salary;
// }

void Employee::setMonthlySalary(int)
{
// range= Salary;
// if ( Salary < 0)
// Salary = 0;
// else
// {
// Salary=Salary;

cout<<"::::"<< Lname << ":" << Fname << " monthly salary is " << Salary << endl;
// }
} [/PHP]


and finally my main file
[PHP]
#include <iostream>
using std::cout;
using std::cin;
using std::endl;


#include "employ.h"

int main()
{

Employee employ1(" Mike","Madox",700);
Employee employ2("Steven","Stevenson",800);


char holdscr;

std::cout << "\n\n\t*** Enter a character and press return to exit the program! ***\n\n\t"<< std::endl;

std::cin >> holdscr;

return 0;
}[/PHP]



First of, I have a couple questions. Why when i un comment the comment lines in my body does it have absolutely no effect on the outcome of the file. When i execute this file i get the correct, last name, first name, but for the int it gives me some crazy #'s and does not carry over what i typed in my main.

How can i fix this?
Oct 16 '08 #1
1 1236
r035198x
13,262 8TB
Your main doesn't use that getter at all so uncommenting it has no effect.
You are getting garbage for the int value because you have commented out the parts that set it's value in the method that is called from the constructor.
Oct 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Vera | last post by:
Hi, I have a very annoying problem, with which I NEED HELP DESPERATELY!! It smells like a bug to me, but I'm not sure. SITUATION This description is a very much simplified version of the real...
3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
1
by: Robert | last post by:
I have two tables (classes and students). Right now, I'm generating a report in asp that shows a list of classes, the enrollment for each class, and how many seats are available (see query below)....
2
by: cm500 | last post by:
I'm very new to databases so bear with me. What I need is a way to track the training for the employees at my firm. I have 40 classes that I will be teaching on various subjects and various...
2
by: Susan Bricker | last post by:
Greetings. Before I begin, I have been stuck on this problem for about a 5 days, now. I have tried and just seem to be not getting anywhere. I know that the explanation is lengthy, but I am a...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
5
by: Benne Smith | last post by:
Hi, I have three enviroments; a development, a testing and a production enviroment. I'm making a big application (.exe), which uses alot of different webservices. I don't use the webservices...
2
by: Andrew S. Giles | last post by:
OK, Ive run my head into this wall for too long. I need help. I am developing an applicaiton in C# to present a user with a GUI to specify a configurable list of machines that he wants to listen...
8
by: Tim Geiges | last post by:
Since I am being challenged with learning c# I figured I could pass some of the pain on to you guys :-) I have another question(this one is important for me to fix before I can get my app to Beta)...
6
by: shaunb | last post by:
Hi, just new to this forum, and i was wondering if anyone could help me. I've got a piece of work to do, i have done the majority of it, just the last, and the most important thing lol, that i am...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.