Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

Program Help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gonzal51 - 02 May 2005 00:43 GMT
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**
Ioannis Vranos - 02 May 2005 01:36 GMT
> 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....
[quoted text clipped - 28 lines]
>  char lastName[20];
>  char password[20];

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

> public:
>
[quoted text clipped - 4 lines]
> };
> //end class

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

> {
>  cout<<"Please Enter Your First Name: "<<endl;
[quoted text clipped - 5 lines]
>  //end setuserdatafunction
> }

void User::changePassword(char password[20],char newPass[20])

> {
>   cout<<"Please enter new password"<<endl;
[quoted text clipped - 11 lines]
>   }
> }

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

> password[20])
> {
[quoted text clipped - 18 lines]
>  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.
gonzal51 - 02 May 2005 03:24 GMT
I was wondering, (while I work on it) what were the problems I was having?

> > 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....
[quoted text clipped - 121 lines]
>
> Just fixed it to compile. I did not check or even run the code.
Ioannis Vranos - 02 May 2005 06:13 GMT
> I was wondering, (while I work on it) what were the problems I was having?

?
gonzal51 - 02 May 2005 13:25 GMT
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. :-)

> > I was wondering, (while I work on it) what were the problems I was having?
>
> ?
Mihajlo Cvetanovic - 02 May 2005 09:27 GMT
> 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.
Ioannis Vranos - 02 May 2005 11:00 GMT
> 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. :-)
Mihajlo Cvetanovic - 02 May 2005 12:05 GMT
> 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 :-)
Ioannis Vranos - 02 May 2005 12:14 GMT
> 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. :-)
Ioannis Vranos - 02 May 2005 12:18 GMT
> For this
>
> class SomeClass
> {
>     public:
>     somefunc();
  };

> SomeClass::somefunc() {}
>
[quoted text clipped - 4 lines]
> 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). :-)
gonzal51 - 02 May 2005 13:30 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.