Solved

Need Help With Code

Posted on 2002-04-12
15
181 Views
Last Modified: 2010-04-02
I am fairly new to C++ and was wondering if anyone could help me out debuggin this code....I am not real sure what to do.

#include<iostream.h>
#include<conio.h>
class ClubMember
{
  private:
    static int count;
    char name[20];
  public:
    ClubMember();
    ~ClubMember();
 };
int ClubMember::count = 0;
ClubMember::ClubMember(char name)
 {
    ++count;
    strcpy(name,name);
    cout<<"ClubMember #"<<count<<" created: ";
    cout<<name<<" has joined the club"<<endl;
 }
ClubMember::~ClubMember(char name)
  {
    --count;
    cout<<name<<" has left the club"<<endl;
    cout<<count<<" ClubMembers left"<<endl;
  }
void main()
{
  {
    cout<<"This program shows five club members"<<endl<<"joining, then leaving, the club"<<endl;
    ClubMember club[5] = {ClubMember("Jim"),ClubMember("Tom"),
         ClubMember("Julie"),ClubMember("Jane"),ClubMember("Kate")};
  }
  getch();
}
0
Comment
Question by:KimZeerip
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +4
15 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6937519
I see no statement of any problem.  What part of this code is giving you trouble?  What part don't you understand?

Can I assume that YOU wrote this code?
0
 

Author Comment

by:KimZeerip
ID: 6937545
When I compile I have 7 errors which are all the same stating : "No constructor could take the source type, or constructor overload resolution was ambiguous"

I am not sure what this means
0
 
LVL 86

Expert Comment

by:jkr
ID: 6937549
>>I see no statement of any problem

ClubMember::ClubMember(char name)

jhance, like http://www.experts-exchange.com/cplusprog/Q.20288160.html (huh, another Kim?), I guess this is homework - the coding styles are too similar, and the task may have been "what is wrong with this code"...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:KimZeerip
ID: 6937635
jkr -- I don't know what your problem is, if you did not want to help me then you should have not added a comment...this is not homework, I am teaching myself C++ and it is an example file that came with the book and I am trying to figure it out!  Not everyone is as gifted as you I guess.  Sorry for trying to learn C++.....if anyone else is willing to help me learn C++ and figure this out, please add a comment or answer!  Thanks
0
 

Author Comment

by:KimZeerip
ID: 6937642
jkr -- I don't know what your problem is, if you did not want to help me then you should have not added a comment...this is not homework, I am teaching myself C++ and it is an example file that came with the book and I am trying to figure it out!  Not everyone is as gifted as you I guess.  Sorry for trying to learn C++.....if anyone else is willing to help me learn C++ and figure this out, please add a comment or answer!  Thanks
0
 
LVL 30

Expert Comment

by:Axter
ID: 6937663
I think jkr is concern that it appears that you have multiple login names, and posted back-to-back similar questions via multiple user id.

You'll find that jkr is one of the more well mannered expert in this topic area.

If you want us to help you, you need to supply as much information as you can.


Post the errors you get.  Post everything you know about the problem.
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6937666
>>and it is an example file that came with the book and I am trying to figure it out!

OK, in this case you should try to get your money back, unless you made *several* typos. However, as you are insisting this is NOT homework, I'll have to believe you. Let's see then:


//#include<iostream.h> // use <iostream> without .h
#include<iostream>
#include<conio.h>

// without that, you needed to use "std::cout"
using namespace std;

class ClubMember
{
 private:
   static int count;
   char name[20];
 public:
//   ClubMember(); default constructor, not needed
   ClubMember(char* name); // THIS is the on you have
   ~ClubMember();
};
int ClubMember::count = 0;
//ClubMember::ClubMember(char name) // 'char' would be a single character
ClubMember::ClubMember(char* name)
{
   ++count;
//   strcpy(name,name);
   strcpyn(name,name, 20); // you only have 20 chars!
   cout<<"ClubMember #"<<count<<" created: ";
   cout<<name<<" has joined the club"<<endl;
}
//ClubMember::~ClubMember(char name) // destructors have no arguments
ClubMember::~ClubMember()
 {
   --count;
   cout<<name<<" has left the club"<<endl;
   cout<<count<<" ClubMembers left"<<endl;
 }
void main()
{
 {
   cout<<"This program shows five club members"<<endl<<"joining, then leaving, the club"<<endl;
   ClubMember club[5] = {ClubMember("Jim"),ClubMember("Tom"),
        ClubMember("Julie"),ClubMember("Jane"),ClubMember("Kate")};
 }
 getch();
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 6937669
Ooops, 'strcpyn' sould be 'strncpy'...
0
 

Author Comment

by:KimZeerip
ID: 6937696
When I compile that code...the output is

"This program shows five club members"<<endl<<"joining, then leaving, the club"

how can I write the code so that the user of the program can input data for the ClubMember # and name??
0
 

Author Comment

by:KimZeerip
ID: 6948380
Figured it out on my own
0
 

Expert Comment

by:ComTech
ID: 6963015
In order to receive a refund, you have to show the answer before we can Delete or PAQ the question, as it stands now, it is no good for a PAQ.

BTW-I would also like to know which account you wish to keep, this one or KimHopper?

Regards,
ComTech
CS Admin @ EE
0
 
LVL 11

Expert Comment

by:griessh
ID: 7012088
Dear KimZeerip

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jkr"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner

BTW: Another part that was failing was:

ClubMember::ClubMember(char* name)
{
  strcpyn(name,name, 20); // you only have 20 chars

The scope of "name" is wrong. Either use another variable name or use "strncpy (this->name, name,20)" ...
0
 
LVL 86

Expert Comment

by:jkr
ID: 7012102
Ooops, no - I am not gonna claim any points for "double account homework" questions...
0
 
LVL 11

Expert Comment

by:griessh
ID: 7012576
- It was no homework
 - You are guilty of solving the problem
 - You found the duplicate account

My verdict:
The defendant will be sentenced to get his comment force-accepted!

<LOL>
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7027906
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 190
Precision Problem in C++ 7 67
Where are the c++ header files to use in Eclipse? 4 73
MFC COM Server not showing  form 4 25
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question