Home > Back-end >  A great god, please help me with my this program problem
A great god, please help me with my this program problem

Time:09-23

Unable to run this program, please help me to see where is the question!
# include & lt; Iostream>
using namespace std;
The class Plant
{
Char * pName.
Int price;
Static int number;
Public:
Plant (char *, int);
To Plant ();
Int getPrice () {return price; }
Char * getName () {return pName. }
Int getNumber () {return number; }
};
Plant: : Plant (char * name, int Price)
{
Name=new char [strlen (pName) + 1);
Strcpy (pName, name);
Price=price;
number++;
}
Plant: : ~ Plant ()
{
The delete [] pName;
Number -;
}
The class Flower: public Plant
{
Char * growthpattern;
Char * department;
Public:
Flower (char * name, int Price, char * growthPattern, char * Department) : Plant (name, Price)
{
GrowthPattern=new char [strlen (growthPattern) + 1);
Strcpy (growthpattern growthpattern);
Department=new char [strlen (Department) + 1);
Strcpy (department, the department);
}
Char * getgrowthpattern () {return growthpattern; }
Char * getdepartment () {return department; }
~ Flower ();
};
Int Plant: : number=0;
Flower: : ~ Flower ()
{
The delete [] growthpattern;
The delete [] department;
}
Int main ()
{
Char NAme [100], gp [100], dp [100];
Int PRice;
Cout<& lt;" Please enter the name of the plant: ";
cin> The NAme;
Cout<& lt;" Please input the price of the plant: ";
cin> PRice;
Cout<& lt;" Please enter the plant growth habit: ";
cin> Gp;
Cout<& lt;" Please enter the plant subjects: ";
cin> Dp.
Flower f1 (NAme, PRice, gp, dp);
Cout<& lt;" Plant name \ \ t t plant price plant growth habit \ t plant subjects "& lt; & lt; Endl;
Cout<& lt; F1. GetName () & lt; & lt;" \ t "& lt; & lt; F1. GetPrice () & lt; & lt;" \ t "& lt; & lt; F1. Getgrowthpattern () & lt; & lt;" \ t "& lt; & lt; F1. Getdepartment () & lt; & lt; Endl;
Cout<& lt;" There are "& lt; & lt; F1. GetNumber () & lt; & lt;" Plant, "& lt; & lt; Endl;
return 0;
System (" pause ");
}

CodePudding user response:

Plant: : Plant (char * name, int Price)
{
PName=new char [strlen (name) + 1);
Strcpy (pName, name);
Price=price;
number++;
}


Flower (char * name, int Price, char * GrowthPattern, char * Department) : Plant (name, Price)
{
Growthpattern=new char [strlen (growthpattern) + 1);
Strcpy (growthpattern growthpattern);
Department=new char [strlen (department) + 1);
Strcpy (department, the department);
}

To try this,,,,
  • Related