| |

VerySource

 Forgot password?
 Register
Search
View: 972|Reply: 7

Help me improve this program ~

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-12 21:30:01
| Show all posts |Read mode
// Define a BOX-like, tetragonal zygote, which requires its volume and surface area to be calculated.

#include <iostream.h>
class BOX
{public:
float x, y, z, v, b;
void Showv ()
{v = x * y * z;
cout << v << endl;};
void Showb ()
(b = 2 * (x * y + x * z + y * z);
     cout << b << endl;};
};
void main ()
{BOX obj;
    obj.x = 10; obj.y = 3; obj.z = 9;
cout << "The volume of this zygote is:";
obj.Showv ();
cout << "The surface area of ​​the zygote is:";
obj.Showb ();
}

I also wrote a program, but I don't think the readability is very good, especially in the BOX class, which one can help me improve it ,,,, and, if you use #include <iostream> as the head File, it runs wrong, why? Thank you!
Reply

Use magic Report

0

Threads

6

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-2-14 02:33:46
| Show all posts
#include <iostream.h>
class BOX
{
public:
BOX (float a, float b, float c): x (a), y (b), z (c);

float GetV ()
{
return x * y * z;
}
Ranch
void GetB ()
{
return 2 * (x * y + x * z + y * z);
}
private:
float x, y, z;
};

void main ()
{
BOX obj (10.0, 3.0, 9.0);
cout << "The volume of this zygote is:" << obj.GetV ();
Ranch
cout << "The surface area of ​​this zygote is:" << obj.GetB ();
}

Probably, that's about it
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-10 12:15:01
| Show all posts
#include <iostream>
using namespace std; // Add this sentence
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Invalid IP Address

Post time: 2020-8-8 14:30:01
| Show all posts
Add one left
public:
BOX(int x1,int y1,int z1)
{x = x1; y = y1; z = z1;}
Then you can BOX ojb(10,3,9);
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-11 10:45:01
| Show all posts
x, y, z, v, b are generally private members
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-11 11:00:01
| Show all posts
Parameter set as private member
Function is set to inline
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-11 11:15:01
| Show all posts
#include<iostream.h>
using namespace std;
class BOX
{
public:
float x,y,z,v,b;
void Showv()
{
v=x*y*z;
cout<<v<<endl;
};

void Showb()
{
  b=2*(x*y+x*z+y*z);
  cout<<b<<endl;};
};

};
void main()
{
    BOX obj;
    obj.x=10;obj.y=3;obj.z=9;
    cout<<"The volume of the box is:";
    obj.Showv();
    cout<<"The surface area of ​​the box is:";
    obj.Showb();
}
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-11 16:00:01
| Show all posts
#include<iostream>

class BOX
{
public:

BOX(float lo,float wi,float hi)
:m_long(lo),m_width(wi),m_height(hi)
{
}

  void BoxVolume()
  {
m_volume=m_long*m_width*m_height;
std::cout<<m_volume<<std::endl;
  };

  void BoxArea()
  {
      m_area=2*(m_long*m_width+m_long*m_height+m_width*m_height);
      std::cout<<m_area<<std::endl;
  };

private:
  float m_long,m_width,m_height;
  float m_volume,m_area;


};

void main()
{
BOX obj(10,3,9);

To
std::cout<<"The volume of the box is:";
         obj.BoxVolume();

         std::cout<<"The surface area of ​​the box is:";
         obj.BoxArea();
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list