Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 8th, 2006, 8:34 PM   #11
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
That knocks out some of the errors. As for toupper, i wanted to use it to make the letters uppercase regardless of what the user inputted for sex, as in either f or m, to be printed out eventually as F or M. It's just for the look, but I don't understand why the compiler complains. But if i put in a one, then in_sex doesn't get assigned to sex. I think i'm just going to take it out.
codylee270 is offline   Reply With Quote
Old Apr 8th, 2006, 8:54 PM   #12
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
int a;
    char s='\0';
    std::cout << "1. Male\n"
              << "2. Female\n";
    do{
    std::cin >> a;
    }while(a!=1&&
    a!=2);
    switch(a)
    {
        case 1:
            s='M';
            break;
        case 2:
            s='F';
            break;
    }
    std::cout<<s;
No?
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old Apr 8th, 2006, 8:55 PM   #13
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
Here's my latest. I've got more errors, which are at the bottom. I tried to figure how i was going to initialize and assign everything in Main, so please look at what I was trying to do and see if this makes sense or even if it's possible, and see how the errors correspond to that.

#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;

class Employee
{
      private:
              int id, years;
              string sex;
              float wage;
      public:
              Employee(int, string, float, int);
              void makeString();
};

Employee::Employee(int in_id, string in_sex, float in_wage, int in_years)
{
         id=in_id;
         sex=in_sex;
         wage=in_wage;
         years=in_years;
}
void Employee::makeString()
{
     string profile[4];
     profile[0]=id;
     profile[1]=sex;
     profile[2]=wage;
     profile[3]=years;
}
         
              
int main() 
{
    int i,id, years;
    string sex;
    float wage;
    
    for(i=0; i<10; i++)
    {
             cout << "Please enter the following Employess information:" << endl;
             cout << "\nEmployee ID No: ";
             cin >> id;
             cout << "\nEmployee Sex: ";
             cin >> sex;
             cout << "\nEmployee Wage: ";
             cin >> wage;
             cout << "\nYears with Company: ";
             cin >> years;
             
             Employee emp[i+1];
             emp[i+1].Employee(id, sex, wage, years);
             emp[i+1].makeString();
    }
    
    system("PAUSE");
    return 0;
}

[Warning] passing `float' for converting 1 of `std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'


In function `int main()': no matching function for call to `Employee::Employee()' . candidates are: Employee::Employee(const Employee&) .

Employee::Employee(int, std::string, float, int)
invalid use of `class Employee'


So, if we can get this working, then i guess the next thing will be to sort based on years with company, which i'm totally clueless as to what to do in terms of the class.

Thanks for all of your help guys!
codylee270 is offline   Reply With Quote
Old Apr 8th, 2006, 9:01 PM   #14
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
Quote:
Employee::Employee(int, std::string, float, int)
Employee emp[i+1];
You're missing 3 other arguments.

As for your warning, I'm not familiar with it so I can't help you there and I wouldn't want to mislead you.
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old Apr 8th, 2006, 9:28 PM   #15
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
adding the std:: in front of the string didn't change any of the errors. And i'm not really sure what you mean by "You're missing 3 other arguments." I was tring to use the emp[i+1] so as the i increments, it'll create another instance for each employee and their data. I wasn't sure if this would work or not. I'm guessing not?? How can i fix it?
codylee270 is offline   Reply With Quote
Old Apr 8th, 2006, 9:38 PM   #16
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
Your constructor requires you to set the 4 arguments, if you want to create a default, i suggest function overloading.

Employee::Employee(int, std::string, float, int) // Means you declare Employee like so...
Employee emp(1, "M", 24, 2)[5]; // The arguments are random, they just mean you have to specify them somehow

for(int i = 0; i < 5; i++)emp[i]; //Set whatever data member you wish wish a member function with access to the class.

std::string is just specifying the namespace, you don't have to use std::string, I use it for my code.
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old Apr 8th, 2006, 9:48 PM   #17
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
changed my main() to try to do what you were saying:

for(i=0; i<10; i++)
    {
             cout << "Please enter the following Employess information:" << endl;
             cout << "\nEmployee ID No: ";
             cin >> id;
             cout << "\nEmployee Sex: ";
             cin >> sex;
             cout << "\nEmployee Wage: ";
             cin >> wage;
             cout << "\nYears with Company: ";
             cin >> years;
             
             Employee emp(id, sex, wage, years)[i+1];
             emp[i+1].makeString();
    }

I get the error: expected `,' or `;' before '[' token.
no match for 'operator[]' in 'emp[(i + 1)]'
codylee270 is offline   Reply With Quote
Old Apr 8th, 2006, 9:59 PM   #18
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
You are trying to create an object of the same name everything the loop loops through.

Employee emp(id, sex, wage, years)[i+1];//Creates an object. Don't do this inside a loop.

do something like this:

Employee emp(id, sex, wage, years)[10]; // There is 10 employees
    for(i=0; i<10; i++)
    {
             cout << "Please enter the following Employess information:" << endl;
             cout << "\nEmployee ID No: ";
             cin >> id;
             cout << "\nEmployee Sex: ";
             cin >> sex;
             cout << "\nEmployee Wage: ";
             cin >> wage;
             cout << "\nYears with Company: ";
             cin >> years;
             emp[i].makeString();
    }

EDIT: Actually, you have a constructor to basically zero out all the values. Why do you have Employee emp(id, sex, wage, years)?
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old Apr 8th, 2006, 10:38 PM   #19
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
Quote:
Originally Posted by jayme
do something like this:

Employee emp(id, sex, wage, years)[10]; // There is 10 employees
    for(i=0; i<10; i++)
    {
             cout << "Please enter the following Employess information:" << endl;
             cout << "\nEmployee ID No: ";
             cin >> id;
             cout << "\nEmployee Sex: ";
             cin >> sex;
             cout << "\nEmployee Wage: ";
             cin >> wage;
             cout << "\nYears with Company: ";
             cin >> years;
             emp[i].makeString();
    }

EDIT: Actually, you have a constructor to basically zero out all the values. Why do you have Employee emp(id, sex, wage, years)?
Does that even set the values for the employee? I think this would work:
Employee emp(id, sex, wage, years)[10]; // There is 10 employees
for(i=0; i<10; i++)
{
	cout << "Please enter the following Employess information:" << endl;
	cout << "\nEmployee ID No: ";
	cin >> id;
	cout << "\nEmployee Sex: ";
	cin >> sex;
	cout << "\nEmployee Wage: ";
	cin >> wage;
	cout << "\nYears with Company: ";
	cin >> years;
	emp[i] = Employee(id,sex,wage,years);
}
And personally, I prefer to not define a constructor which initializes the values to zero, as no actual person would have those statistics (hence why allow that to be created). Theres nothing wrong IMHO with being forced to use the correct constructor.

As to the toupper(int) function, it takes an ASCII value (as an int, rather than char; the implicit cast is not an issue here), and returns the uppercase equivalent. I believe it's defined in <cctype>.
Jimbo is offline   Reply With Quote
Old Apr 8th, 2006, 10:56 PM   #20
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Quote:
Originally Posted by jayme
Employee emp(id, sex, wage, years)[10];
I don't think this is the right syntax to declare and initialize an array.
I guess it's something like:
Employee emp[10]={
                   Employee(id,sex,wage,years)
                           };
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:01 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC