using class

Write your question here.
Im writing a code about plants by using class, after i wrote the header file and cpp file,and afert excute my code i had that kind of error message

'"c:\users\a104\documents\visual studio 2010\Projects\Plants\Debug\Plants.exe"'
is not recognized as an internal or external command,
operable program or batch file.

Press any key to continue . . .

my code is there below. thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//Plants.h
#include<iostream>
#include<string>
using namespace std;

class Plant
{
private:
	 string _genusAndSpecies;
	 string _type;
	 float _avgHeight;

public:
	Plant();
	~Plant();
	void setPlantInfo(string genusAndSpecies,string type ,float avgHeight);
	void displayPlant() const;
}

=========================================
// Plants.cpp

#include "Plants.h"

	Plant::Plant()
	{
		_genusAndSpecies  ;
		_type  ;
		_avgHeight = 0;
	}
	Plant::~Plant()
	{}
	void  Plant::setPlantInfo(string genusAndSpecies,string type ,float avgHeight)
	{ 
		_genusAndSpecies =genusAndSpecies ;
		_type = type;
		_avgHeight = avgHeight
			;


	}
	void  Plant::displayPlant() const
	{ cout <<"Genus and Species: " <<_genusAndSpecies << endl;
	  cout <<"Type:  " <<_type  << endl;
	  cout <<"Average height: " << _avgHeight << endl ;
	}
=============================================
//driver.cpp
#include "Plants.cpp"

int main()
{ Plant p1;
  Plant p2;
  Plant p3;
  string genusAndSpecies = "ddddd";
  string type  = "AA";
  float avgHeight = 0.0;
  cout <<"Enter information about the first plant." << endl;

  cout <<"Genus and Species: " ;
  cin >> genusAndSpecies ;
		
  cout <<"Type:  " ;
  cin >>type  ;
  cout <<endl;

  cout <<"Average height: " ;
  cin >> avgHeight ;

  p1.setPlantInfo(genusAndSpecies,type , avgHeight);
  p2.setPlantInfo(genusAndSpecies,type , avgHeight);
  p3.setPlantInfo(genusAndSpecies,type , avgHeight);

  p1.displayPlant();
  p2.displayPlant();
  p3.displayPlant();
	return 0;
}
 
First of all in your main function you ask for the information for the 1st plant and you set that to all the plants.

I think your error must be in mistypes because what it's basically telling you is that there is no such file
In your main driver:

Should be
#include "Plants.h"
not
#include "Plants.cpp"

In your header you are missing a semicolon after your last curly brace. Also might want to start now with #include guards, makes for a good practice.

After these changes it compiles and runs just fine(g++). What compiler are you using? Seems like an issue with your IDE looking in the wrong directory for your executable.
Last edited on
Thanks a lot both of you 'johny31' and 'pfunk35' yes I made those changes and it works just fine. the problem here im still not familair with names or who we call the stuff here in c++. because I dont know how to answer you quesyion regarding what complier im using.
thanks again
Topic archived. No new replies allowed.