Panel Class

Outdoor Advertising Panels” have the following characteristics:
length–A Constantnumeric value indicating the lengthof the panel in meters.(Defaults to 5 )

width–A numeric value indicating the width of the panel in meters.( Between 2 and 5 inclusively. Defaults to 3 )

height–A numeric value indicating the height of the panel from the ground in meters.(Between 1.5 and 2.8 inclusively. Defaults to 1.5)

location–The name of the citywhere the panel is located.(Maximum of 30 characters.Defaults to Empty String )

panelCount–A commoninformation known toall object of the class. It will be used to hold the number of object created.Thus it should be incremented when an
object is created and decremented when an object is destroyed.(Defaults to 0)

Create class Panelthat will be used by an advertisingcompany to manage its “Outdoor Advertising Panels” Your class should include the following member functions:

A constructor with default arguments.

A“setPanel”functionthat sets all data members of a Panel object. (integrity checks required)

A “getLocation”functions that returns the location data of a Panel object
.

A function that prints to the screen the contents of the data members.(Cascading capabilities required).

A function that calculates the surface of the panel in square meters. (surface=length*width)Your design should include:

An external function“incHeight” that will be used to increase the “height” data member by a certain value
.
This external function should be able to
access by name all members of your class
.
Write a program to test y
our class by creating “advertising panels” objects as following:

Ask the user to enter the number of panels to create.

Dynamically
create the objects for the requested number of panels.

Verify whether the objects creation is successful.

Ask the user to fil
l the data for all created objects.

Finally, print on the screen (using the print member function) the information of all “advertising
Panels” located in the city of
Beirut

[code]
#include <iostream>
#include <cstring>
using namespace std;

class Panel
{
private:
const int lenght;
int width;
double height;
char loc[30];
static int count;

public:
Panel(int,int,double,char[]);
void printall();
char getlocation(char loc []);

friend void incheight(Panel p,int val);
static int count;
Panel():lenght()
{
width=3;
height-1.5;
loc[0]='\0';
}
void setpanel(int w, double h,char location[])
{
width=w >=2 && w<=5?w:3;
height=h>= 1.5 && h <= 2.8 ? h : 1.5;
location=loc;
}
char getlocation()
{
for(int i=0;i>30;i++)

return loc[i];
}
int surface()
{
int s=0;
s=lenght*height;
return s;
}
};


char Panel::getlocation()
{
return loc[30];
}

void Panel::printall()
{

cout<<"The Width is:"<<width<<endl;
cout<<"The Height is:"<<height<<endl;
cout<<"The Location is:"<<loc<<endl;
}

int main()
{
cout<<"Enter the number of Panel to create:";
int s;
cin>>s;
Panel * x;
x=new Panel[s];
cout<<"The Number of Panel Created is :"<<s<<endl;

}


now i'm condused i dont know anymore what i have done and what is still missing and if i have any logic errors
confused ***
So far you have created a Panel class and created an array with panels.

Now you need to create a function where the user can enter the data for the panels.

Finally, print on the screen (using the print member function) the information of all “advertising
Panels” located in the city of
Beirut.

It would be easier if you use proper names for your vars, like num_panels instead of s or panels instead of x.


how should i create the function that permit to the user to enter the data?? can you help me with the code
How should i create the function that permit to the user to enter the data??


Before you can do this you have to fix to Panel class first. Did you actually write this class ?
yes i wrote but i'm blocked and i dont know how to finish it can you please fix the errors and help me finish it. I'm a student
What is actually the problem. The instructions are clear and precise.

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
/*
Outdoor Advertising Panels” have the following characteristics:

  * length      – A Constant numeric value indicating the length of the panel in meters.(Defaults to 5 )
  * width       – A numeric value indicating the width of the panel in meters.( Between 2 and 5 inclusively. Defaults to 3 )
  * height      – A numeric value indicating the height of the panel from the ground in meters.(Between 1.5 and 2.8 inclusively. Defaults to 1.5)
  * location    – The name of the citywhere the panel is located.(Maximum of 30 characters.Defaults to Empty String )
  * panelCount  – A commoninformation known toall object of the class. It will be used to hold the number of object created.Thus it should be incremented when an
                  object is created and decremented when an object is destroyed.(Defaults to 0)

Create class Panel that will be used by an advertisingcompany to manage its “Outdoor Advertising Panels” 
Your class should include the following member functions:

  * A constructor with default arguments.
  * A “setPanel” function that sets all data members of a Panel object. 
    (integrity checks required)

  * A “getLocation”functions that returns the location data of a Panel object
  * A function that prints to the screen the contents of the data members.
    (Cascading capabilities required).
  * A function that calculates the surface of the panel in square meters. 
    (surface=length*width)
    Your design should include:
      * An external function“incHeight” that will be used to increase the “height” 
        data member by a certain value

    This external function should be able to
    access by name all members of your class

*/


I would write like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

using namespace std;

class Panel
{
private:
  const int length = 5; //meters
  int width;
  float height;
  string location;
  static int panelCount;
public:
  Panel(int width = 3, float height = 1.5, string location = "");
  void setPanel(int width, float height, string location);
  void print();
  string getLocation();
  int getSurface();
  friend void incHeight();
};


Maybe you can finish (implement) the class - my lunch break is over.
dear thomas I still have some questions
first the string getLocation how do we write the function ?? and can it be char instead of string because we didn't learn the string..
And the getSurface function what is it for ??

thank you

first the string getLocation how do we write the function ?? and can it be char instead of string because we didn't learn the string..


Here it is:

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
#include <iostream>
#include <string>

using namespace std;

class Panel
{
private:
  const int length; //meters
  int width;
  float height;
  char location[31];
  static int panelCount;
public:
  Panel(int width = 3, float height = 1.5, char location[31] = "");
  void setPanel(int width, float height, char location[31]);
  void print();
  char* getLocation();
  int getSurface();
  friend void incHeight(Panel panel, int amount);
};

Panel::Panel(int width, float height, char location[31]):length(5)
{
  this->height = height;
  this->width = width;
  strncpy(this->location, location, sizeof(location));
}

void Panel::setPanel(int width, float height, char location[31])
{
  this->height = height;
  this->width = width;
  strncpy(this->location, location, sizeof(location));
}

void Panel::print()
{
  // print data here
}

char* Panel::getLocation()
{
  return location;
}

int Panel::getSurface()
{
  return length * width;
}

void incHeight(Panel panel, int amount)
{
  panel.height += amount;
}

void main()
{
  system("pause");
}


And the getSurface function what is it for ??


Well it calculates the surface of the panel.

Why don't you start learning with an easier project. It seems you have not mastered the basics yet?
Topic archived. No new replies allowed.