![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#12 | |
|
Professional Programmer
|
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;
__________________
▄▄▄▄ Quote:
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! ▄▄▄▄ |
|
|
|
|
|
|
#13 |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
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! |
|
|
|
|
|
#14 | ||
|
Professional Programmer
|
Quote:
Employee emp[i+1]; 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:
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! ▄▄▄▄ |
||
|
|
|
|
|
#15 |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
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?
|
|
|
|
|
|
#16 | |
|
Professional Programmer
|
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:
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! ▄▄▄▄ |
|
|
|
|
|
|
#17 |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
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)]' |
|
|
|
|
|
#18 | |
|
Professional Programmer
|
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:
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! ▄▄▄▄ |
|
|
|
|
|
|
#19 | |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
Quote:
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);
}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>. |
|
|
|
|
|
|
#20 | |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Quote:
I guess it's something like: Employee emp[10]={
Employee(id,sex,wage,years)
};
__________________
PFO - My daily dose of technology. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|