我的同行告诉我,我遵循的实施方式是一种危险的做法。我在主要方法和函数中为变量取了相同的名称。我的意思是只要它有效,不是吗?你会怎么做?
谢谢。
#include <iostream>
#include <string>
#include <sstream>
#include "Three.h"
Three::Three(void)
{
}
Three::~Three(void)
{
}
void Three::rect (int& ar, int&vl, int len, int wid, int hgt)
{
ar = (len * wid) * 2 + (len+wid) * 2 * hgt;
vl = len * wid * hgt;
cout << "Area is " << ar << " square feet that contains " << vl << " cubic feet." << endl;
}
char qt;
int main (int, char**)
{
int len = 0;
int wid = 0;
int hgt = 0;
int ar = 0;
int vl = 0;
do
{
cout << "Length of House (ft): " << endl;
std::cin >> len;
cout << "Width of House (ft): " << endl;
std::cin >> wid;
cout << "Height of House (ft): " << endl;
std::cin >> hgt;
Three three;
three.rect (ar, vl, len, wid, hgt);
cout << "q, to quit" << endl; //My own quit statement
std::cin >> qt;
}
while (qt != 'q');
}