#include (iostream.hpp)

class Stocks { public: Stocks( int price); ~Stocks(); int get_price() const {return pps;} int set_price() const {pps;} int the_price_is (int pps); int pps; } int main() { Stocks AMX (35) cout << " Hello, please enter a symbol.\n"; if cin>> AMX; cin.ignore; cin.get; AMX.the_price_is cout<<" 35.\n"; return 0; } Well, I know this is not the right way to do this but here is the problem. When I tried to put in the constructor and destructor, they caused alot more errors. But also it says I can't declare a new class, whcih I am not, the only thing I am creating is an object (AMX, the stock symbol for American Express). So how do I implement this code? And one unrrelated question: what does it mean by keeping this place student friendly? Does it mean don't expect people to create code for you? Thanks[code=C++]#include (iostream.hpp)

class Stocks
{
public:
Stocks( int price);
~Stocks();
int get_price() const {return pps;}
int set_price() const {pps;}
int the_price_is (int pps);
int pps;
}


int main()
{
Stocks AMX (35)
cout << " Hello, please enter a symbol.\n";

if
cin>> AMX;
cin.ignore;
cin.get;
AMX.the_price_is
cout<<" 35.\n";
return 0;
}

Well, I know this is not the right way to do this but here is the problem. When I tried to put in the constructor and destructor, they caused alot more errors. But also it says I can't declare a new class, whcih I am not, the only thing I am creating is an object (AMX, the stock symbol for American Express). So how do I implement this code? And one unrrelated question: what does it mean by keeping this place student friendly? Does it mean don't expect people to create code for you? Thanks

start quote:

#include (iostream.hpp)

class Stocks
{
      public:
      Stocks( int price);
      ~Stocks();
      int get_price() const {return pps;}
      int set_price() const {pps;}
      int the_price_is (int pps);
      int pps;
}


int main()
{
    Stocks AMX (35)
    cout << " Hello, please enter a symbol.\n";

    if
    cin>> AMX;
    cin.ignore;
    cin.get;
    AMX.the_price_is
    cout<<" 35.\n";
return 0;
}

Well, I know this is not the right way to do this but here is the problem. When I tried to put in the constructor and destructor, they caused alot more errors. But also it says I can't declare a new class, whcih I am not, the only thing I am creating is an object (AMX, the stock symbol for American Express). So how do I implement this code? And one unrrelated question: what does it mean by keeping this place student friendly? Does it mean don't expect people to create code for you? Thanks

That's exactly what it means. It means that a student must do their own work and not expect the members to code something up for them to turn in without any effort.

I think I see part of your issue, but you'll have to fix your code-tag in order for me to tell...

[code=C++]#include (iostream.hpp)

class Stocks
{
public:
Stocks( int price);
~Stocks();
int get_price() const {return pps;}
int set_price() const {pps;}
int the_price_is (int pps);
int pps;
}


int main()
{
Stocks AMX (35)
cout << " Hello, please enter a symbol.\n";

if
cin>> AMX;
cin.ignore;
cin.get;
AMX.the_price_is
cout<<" 35.\n";
return 0;
}

Ok Just didn't want to be a hassle. :) I did not figure I was, but just wanted to make sure. And sorry for not catching on with the code wrap around. Thanks

When you define a class, you must place a semi-colon after the class' closing brace. If you do not, the compiler thinks you are still defining the class and goes completely nuts while working on the rest of your code.

//in class.h file
class example {
private:

protected:

public:
example()  //<--constructor
~example()  //<--destructor
};  <---- semi-colon required
//in class.cpp file
#include class.h
/* other required inclusions */

example::example() { //<--constructor
  /* required actions */
}

example::~example() { //<--destructor
  /* required actions */
}

I suspect there will be more errors related to your missing semi-colon on line 17 as well as the structure of your if statement starting on line 20. Also, I see 3 function calls that are not written correctly. For example, on line 24 you attempt to call Stocks::the_price_is() incorrectly. Study up on functions and fix your calls as well.

#include (iostream.hpp) 

class Stocks
{
public:
Stocks( int price);
~Stocks();
void set_price (int price);

private:
int pps ();
};


Stocks::Stocks (int sp)
{
  pps=price;
}
Stocks:~Stocks()
{
}


int main()
{
Stocks AMX (35)
cout << " Hello, please enter a symbol.\n";


cin>> AMX;
cin.ignore;
cin.get;
AMX.pps 
cout<<" 35.\n";
return 0;
}

I redid the code so it was a little more simple. Is there any way I could make this work?

I'm not sure what you are trying to accomplish with this code, but whatever it is, you didn't accomplish it. Have you even tried to compile this? This comes across as un-thought-out junk thrown out there to see what happens. Most of the errors are very elementary things that you should have learned straight away when you started learning the language. See comments:

#include (iostream.hpp)

This is an invalid include, it should be #include <iostream> Also, something is missing here, where is/are your namespace resolution statement(s)? They're not necessary if you resolve directly within your code, but you don't.

class Stocks
{
public:
Stocks( int price); //specified constructor, where is default?
~Stocks();
void set_price (int price);

private:
int pps ();
};

The structure of the class itself is fairly accurate. But, you only have a specified constructor and no default constructor. I hope you plan to specify the initial value of every "Stocks" object you create at creation time.

In addition, Line 9 is a private member function prototype. Based on what I see elsewhere it should be a member variable declaration. Lose the parentheses.

Stocks::Stocks (int sp)  //<- function header
{
  pps=price;
}

This function definition does nothing useful. The variables "price" and "pps" do not exist. If you want to use a parameter in a function, you need to use the proper name as defined by the function header. In this case, that name is "sp", not "price". Also, as defined, "pps" is a function not a variable so the assignment is not allowed.

Stocks:~Stocks()
{
}

This is a syntax error, you did not resolve the scope properly. The scope-resolution operator is " :: ".

int main()
{
Stocks AMX (35)
cout << " Hello, please enter a symbol.\n";


cin>> AMX;
cin.ignore; //invalid function call to std::cin::ignore()
cin.get;  //another invalid function call
AMX.pps //invalid function call to private member that shouldn't be a function anyway
cout<<" 35.\n";  //the purpose of this is?????
return 0;
}

First, the good:
You specified main() as an int and it returns 0 upon successful completion.

Now, the bad:
You are missing a semi-colon on line 3, otherwise it is syntactically correct.

Line 7 is syntactically correct, but will not work. You have not overloaded the extraction operator to work directly with your Stocks class. As a result, this does nothing useful.

Lines 8, 9 and 10 are all invalid function calls. Line 10 wouldn't work even if it was written correctly. Not only is the semi-colon missing, but you are attempting to directly access "pps", a private member, which is illegal.

I'm not real sure what the purpose of Line 11 is. Are you trying to show the stock's price? If so, that's not what you're getting. If you want the value of a variable, you need to use the variable.

Again, I advise you to do some research on C++ functions and C++ classes.

You know I think that I overcomplicated this just so I could branch out intead of using the example. I was trying to list the price of various stocks. I was going to just start off with one, then expand from there. But I think I better find a better example sorry.I really appreciate your help on various post. Sorry for being a pain if I was.Thanks

No pain. Just make sure you pay attention to what you are doing. Programming isn't just entering a bunch of symbols into a file and hoping they'll work. Programming is about thinking through a problem and using the syntax of the chosen language to describe the required actions.

It's kind of like translating English to Spanish or French, you're just translating to "computer" instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.