473,397 Members | 1,949 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,397 software developers and data experts.

Program Help

Hi, I'm a student learning C++ and my professor isn't much help, her view is
if you dont get it I ain't helping you....

We are supposed to do a basic program as a logon system. I got as far as I
could and came up with some errors I could not understand.

Any Help would be appreciated.
Using: MS Visual Studio .Net 2003
Language: C++
Program centers around: Classes
**CODE**
/*
Name: Matthew Gonzalez
Prog Name: gonzalez_PA10
Date: 4/27/05
Purpose: Classes
*/

#include <iostream>
using namespace std;

//class
class User
{
private:

int userId;
char firstName[20];
char lastName[20];
char password[20];
public:

void setUserData(char firstName[20],char lastName[20],char password[20]);
void changePassword (char password[20],char newPass[20]);
void displayUser(int userId,char firstName[20],char lastName[20], char
password[20]);
};
//end class
User::setUserData(char firstName[20],char lastName[20],char password[20])
{
cout<<"Please Enter Your First Name: "<<endl;
cin>>firstName[20];
cout<<"Please Enter your Last Name: "<<endl;
cin>>lastName[20];
cout<<"Please Enter your Password: "<<endl;
cin>>password[20];
//end setuserdatafunction
}
User::changePassword(char password[20],char newPass[20])
{
cout<<"Please enter new password"<<endl;
cin>>newPass[20];

if(password[20]==newPass[20])
{
cout<<"Your password is the same. No Change will occur."<<endl;
}
else
{
if(password[20]!=newPass[20])

newPass[20]=password[20];
}
}
User::displayUser(int userId,char firstName[20],char lastName[20], char
password[20])
{
cout<<"The User id is: "<<userId<<endl;
cout<<"The First name is: "<<firstName[20]<<endl;
cout<<"The Last name is: "<<lastName[20]<<endl;
cout<<"The password is: "<<password[20]<<endl;
//end display user function
}

int main()
{
//user object
User logon;
int userId;
char firstName[20];
char lastName[20];
char password[20];
char newPass[20];
char answer;

cout<<"Please enter a user Id: "<<endl;
cin>>userId;
logon.setUserData(char firstName[20],char lastName[20],char password[20]);
cout<<"Do you want to change your password? Enter Y or N: "<<endl;
cin>>answer;
//if
if(answer=='y')
{
logon.changePassword(char password[20],char newPass[20]);
logon.displayUser(int UserId,char firstName[20],char lastName[20],char
password[20]);
}
else

if(answer=='n')
{
logon.displayUser(int UserId,char firstName[20],char lastName[20],char
password[20]);
}
//endif

return 0;
}

**END CODE**

Nov 17 '05 #1
10 1285
gonzal51 wrote:
Hi, I'm a student learning C++ and my professor isn't much help, her view is
if you dont get it I ain't helping you....

We are supposed to do a basic program as a logon system. I got as far as I
could and came up with some errors I could not understand.

Any Help would be appreciated.
Using: MS Visual Studio .Net 2003
Language: C++
Program centers around: Classes
**CODE**
/*
Name: Matthew Gonzalez
Prog Name: gonzalez_PA10
Date: 4/27/05
Purpose: Classes
*/

#include <iostream>
using namespace std;

//class
class User
{
private:

int userId;
char firstName[20];
char lastName[20];
char password[20];

Using std::string instead of char arrays would be better.

public:

void setUserData(char firstName[20],char lastName[20],char password[20]);
void changePassword (char password[20],char newPass[20]);
void displayUser(int userId,char firstName[20],char lastName[20], char
password[20]);
};
//end class
void User::setUserData(char firstName[20],char lastName[20],char password[20])
{
cout<<"Please Enter Your First Name: "<<endl;
cin>>firstName[20];
cout<<"Please Enter your Last Name: "<<endl;
cin>>lastName[20];
cout<<"Please Enter your Password: "<<endl;
cin>>password[20];
//end setuserdatafunction
}
void User::changePassword(char password[20],char newPass[20])
{
cout<<"Please enter new password"<<endl;
cin>>newPass[20];

if(password[20]==newPass[20])
{
cout<<"Your password is the same. No Change will occur."<<endl;
}
else
{
if(password[20]!=newPass[20])

newPass[20]=password[20];
}
}
void User::displayUser(int userId,char firstName[20],char lastName[20], char
password[20])
{
cout<<"The User id is: "<<userId<<endl;
cout<<"The First name is: "<<firstName[20]<<endl;
cout<<"The Last name is: "<<lastName[20]<<endl;
cout<<"The password is: "<<password[20]<<endl;
//end display user function
}

int main()
{
//user object
User logon;
int userId;
char firstName[20];
char lastName[20];
char password[20];
char newPass[20];
char answer;

cout<<"Please enter a user Id: "<<endl;
cin>>userId;
logon.setUserData(firstName, lastName, password);
cout<<"Do you want to change your password? Enter Y or N: "<<endl;
cin>>answer;
//if
if(answer=='y')
{
logon.changePassword(password, newPass);
logon.displayUser(userId, firstName, lastName, password);

}
else

if(answer=='n')
{
logon.displayUser(userId, firstName, lastName, password);
}
//endif

return 0;
}

Just fixed it to compile. I did not check or even run the code.
Nov 17 '05 #2
I was wondering, (while I work on it) what were the problems I was having?
"Ioannis Vranos" <iv*@remove.this.grad.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
gonzal51 wrote:
Hi, I'm a student learning C++ and my professor isn't much help, her view is if you dont get it I ain't helping you....

We are supposed to do a basic program as a logon system. I got as far as I could and came up with some errors I could not understand.

Any Help would be appreciated.
Using: MS Visual Studio .Net 2003
Language: C++
Program centers around: Classes
**CODE**
/*
Name: Matthew Gonzalez
Prog Name: gonzalez_PA10
Date: 4/27/05
Purpose: Classes
*/

#include <iostream>
using namespace std;

//class
class User
{
private:

int userId;
char firstName[20];
char lastName[20];
char password[20];

Using std::string instead of char arrays would be better.

public:

void setUserData(char firstName[20],char lastName[20],char password[20]); void changePassword (char password[20],char newPass[20]);
void displayUser(int userId,char firstName[20],char lastName[20], char
password[20]);
};
//end class


void User::setUserData(char firstName[20],char lastName[20],char

password[20])
{
cout<<"Please Enter Your First Name: "<<endl;
cin>>firstName[20];
cout<<"Please Enter your Last Name: "<<endl;
cin>>lastName[20];
cout<<"Please Enter your Password: "<<endl;
cin>>password[20];
//end setuserdatafunction
}
void User::changePassword(char password[20],char newPass[20])
{
cout<<"Please enter new password"<<endl;
cin>>newPass[20];

if(password[20]==newPass[20])
{
cout<<"Your password is the same. No Change will occur."<<endl;
}
else
{
if(password[20]!=newPass[20])

newPass[20]=password[20];
}
}


void User::displayUser(int userId,char firstName[20],char lastName[20],

char
password[20])
{
cout<<"The User id is: "<<userId<<endl;
cout<<"The First name is: "<<firstName[20]<<endl;
cout<<"The Last name is: "<<lastName[20]<<endl;
cout<<"The password is: "<<password[20]<<endl;
//end display user function
}

int main()
{
//user object
User logon;
int userId;
char firstName[20];
char lastName[20];
char password[20];
char newPass[20];
char answer;

cout<<"Please enter a user Id: "<<endl;
cin>>userId;


logon.setUserData(firstName, lastName, password);
cout<<"Do you want to change your password? Enter Y or N: "<<endl;
cin>>answer;
//if
if(answer=='y')
{


logon.changePassword(password, newPass);
logon.displayUser(userId, firstName, lastName, password);

}
else

if(answer=='n')
{


logon.displayUser(userId, firstName, lastName, password);
}
//endif

return 0;
}

Just fixed it to compile. I did not check or even run the code.

Nov 17 '05 #3
gonzal51 wrote:
I was wondering, (while I work on it) what were the problems I was having?


?
Nov 17 '05 #4
gonzal51 wrote:
I was wondering, (while I work on it) what were the problems I was having?
void User::setUserData(char firstName[20],char lastName[20],char
When you omit return type (void in this case) the default type is int,
so the compiler expects that you actually return something (return 0).
Since you don't return anything compiler calls it an error.
logon.setUserData(firstName, lastName, password);


When you call a function you put arguments in argument list. But "char
firstName[20]" is not an argument. "firstName" is an argument. To the
compiler "char firstName[20]" looks like a declaration, but the whole
line doesn't look like anything recognizable, that's why it's confused
and reports an error.
Nov 17 '05 #5
Mihajlo Cvetanovic wrote:
When you omit return type (void in this case) the default type is int,
so the compiler expects that you actually return something (return 0).
Since you don't return anything compiler calls it an error.

I think you are probably talking about pre-standard C++. By omitting the return type, no
int is implied, it is an error. :-)
Nov 17 '05 #6
Ioannis Vranos wrote:

I think you are probably talking about pre-standard C++. By omitting the
return type, no int is implied, it is an error. :-)


Alas, VC71 assumes int and gives only warnings, C4183 for member
functions and C4508 for global functions, but it wouldn't be an error to
treat is as such :-)
Nov 17 '05 #7
Mihajlo Cvetanovic wrote:
Alas, VC71 assumes int and gives only warnings, C4183 for member
functions and C4508 for global functions, but it wouldn't be an error to
treat is as such :-)

Let's use some simple code:
class SomeClass
{
public:
void somefunc();
}

SomeClass::somefunc() {}
int main()
{
}

Do you get such warnings for this?
For this

class SomeClass
{
public:
somefunc();
}

SomeClass::somefunc() {}
int main()
{
}

I get such a warning, but it is followed by bizarre errors and does not compile either. :-)
Nov 17 '05 #8
Ioannis Vranos wrote:
For this

class SomeClass
{
public:
somefunc(); };
SomeClass::somefunc() {}
int main()
{
}

I get such a warning, but it is followed by bizarre errors and does not
compile either. :-)

I had omitted the ';' in the class definition. Yes you are right, it gives such a warning
and compiles. However this is not standard C++ behaviour, you may consider it as a system
extension (which probably would be better to be fixed sooner or later). :-)
Nov 17 '05 #9
I meant, while I load it into my visual.NET and physically look at it as
well as changes you've made (thanks!). Although I found that while it
compiles, I can enter an userId, and FirstName, but soon after it shows the
other outputs, i'm guessing its a problem with my SetUserData function. Such
is what I meant by working on it. :-)
"Ioannis Vranos" <iv*@remove.this.grad.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
gonzal51 wrote:
I was wondering, (while I work on it) what were the problems I was
having?
?

Nov 17 '05 #10
Thanks for the info. I appreciate it.

"> >> logon.setUserData(firstName, lastName, password);

When you call a function you put arguments in argument list. But "char
firstName[20]" is not an argument. "firstName" is an argument. To the
compiler "char firstName[20]" looks like a declaration, but the whole
line doesn't look like anything recognizable, that's why it's confused
and reports an error.

Nov 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
2
by: stanlo | last post by:
Hallo to everyone, i am just begining to learn c++ even though i did pascal when i studied mathematics in the univesity.i just took on my self a project which writing a c++ program which does...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
by: Willing 2 Learn | last post by:
Below is a program I did to recognize a Finite State Automata for ASCII (J+H)*. I got that one working but im having trouble getting the NFA program to work. I really desperately need help! My...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
12
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
0
by: ashishbathini | last post by:
Hi guys here is my problem ... this is the source code I Have , honestly I hav no idea how it works bcos its too complicated for me .... but my problem is ... i hav a freq comonent in it .......
9
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.