员工测试驱动程序数据结构
Employee Test Driver Data Structures
我将使用什么来定义公共和私有之外的这些变量?恩努姆?
本节的说明如下:
默认构造函数。请记住,Address 的默认构造函数具有以下初始值: 地址到"99999日落大道" , "比佛利山庄", "CA", "99999">
4 个私有字符串实例变量:街道、城市、州、邮编 具有 4 个参数的构造函数:一个用于街道,一个用于城市,一个用于州,一个用于 zip。
打印地址((:它打印街道,城市,州和邮政编码
这是我到目前为止得到的
class Address
{
public:
Address();
Address(City defaultCity, State defaultState, Street defaultStreet, Zip, defaultZip);
int getCity();
int getState();
int getStreet();
int getZip();
int printAddress();
private:
int Street, City, State, Zip;
};
Address :: Address(City defaultCity, State defaultState, Street defaultStreet, Zip, defaultZip);
{
defaultCity = City
defaultState = State
defaultStreet = Street
defaultZip = Zip
}
Address::Address()
{
Street = "99999 Sunset Boulevard,";
City = "Beverly Hills,";
State = "CA,";
Zip = "99999";
}
int Address::getCity()
{
return City;
}
int Address::getState()
{
return State;
}
int Address::getStreet()
{
return Street;
}
int Address::getZip()
{
return Zip;
}
int Address::printAddress()
{
return Street, City, State, Zip;
};
另外,当他说"打印"时,我认为他的意思是显示对吗?
谢谢
我会这样做:
#include <iostream>
#include <string>
/********************
* File: Main.cpp *
********************/
/*
* For simplicity I put it all in one file.
*/
class Address
{
public:
explicit Address();
explicit Address(const std::string& city, const std::string& state,
const std::string& street, const std::string& zip);
const std::string& getCity() const;
const std::string& getState() const;
const std::string& getStreet() const;
const std::string& getZip() const;
void printAddress() const;
private:
std::string street;
std::string city;
std::string state;
std::string zip;
};
// Default Constructor
Address::Address() :
city("Beverly Hills"),
state("CA"),
street("99999 Sunset Boulevard"),
zip("99999")
{ }
Address::Address(const std::string& city, const std::string& state,
const std::string& street, const std::string& zip) :
city(city), state(state), street(street), zip(zip)
{ }
const std::string& Address::getCity() const
{
return city;
}
const std::string& Address::getState() const
{
return state;
}
const std::string& Address::getStreet() const
{
return street;
}
const std::string& Address::getZip() const
{
return zip;
}
void Address::printAddress() const
{
std::cout << street << ", " << city << ", "
<< state << ", " << zip << std::endl;
};
int main(int argc, char* argv[]) {
Address defaultAddress;
defaultAddress.printAddress();
Address customAddress("Cologne", "NRW", "Domplatz 1", "D-50668");
customAddress.printAddress();
return 0;
}
编辑:
解释一些变化。
查看类声明的私有部分。您将成员声明为
int
尽管它们应该是字符串。我纠正了这一点。在构造函数中,应使用初始化列表来初始化成员。
在构造函数参数列表中,您使用了单词
City
、State
、Street
和Zip
,就好像它们是类型一样。他们不是。这些参数的类型为 std::string。或者就我而言,我选择了const std::string&
因为如果两者都可行,我更喜欢通过引用传递而不是按值传递。如果方法不更改对象,则可以
const
声明它们,以便也可以在类或 const 引用的 const 实例上调用它们。在这个例子中,我在声明getter时就是这样做的。我认为打印后不需要向调用方返回任何内容,因此我将返回类型更改为
void
。我添加了一个 main 函数来测试类。
关于这些差异可能还有很多话要说,但我认为今晚已经足够了。
干杯!
相关文章:
- googletest:测试太大的数据结构
- 员工测试驱动程序数据结构
- 为 Sql 服务器实现 odbc 包装器.将数据库数据读取为字符或要求驱动程序将数据转换为 C 类型
- 用于向公众公开数据成员的帮助程序结构
- 当要测试的函数需要用户输入时,如何制作驱动程序函数?
- Mongodb Cxx 驱动程序测试在发布版本中崩溃 [ 在调试中工作正常]
- 视窗驱动程序,旋转锁采集和条件测试
- 使用示例代码测试 mongocxx c++ 驱动程序
- CAD程序的数据结构.鼠标拾取和渲染一个数据
- 如何使用 C++ 驱动程序在 MongoDB 中使用 UserException 处理数据类型错误
- 为什么Visual Studio说如果我的程序中没有编写任何数据结构代码,我就会出现堆栈溢出?C++
- 如何为搜索应用程序找到正确的数据结构
- 卡在C++数据结构程序中
- 具有多态性和不同数据结构的程序设计
- "std::"具有排序/排序、存在测试和头/尾访问的数据结构?
- 我什么时候需要一个无锁的数据结构来跨音频应用程序中的线程读取/写入数据
- 运行select语句时,Firebird ODBC驱动程序数据被截断
- 使用RtlCopyMemory在驱动程序中复制数据
- 是否有标准的图形数据结构可用于基准测试?
- 在我的神经网络程序中使用的最有效的数据结构是什么?我的程序需要动态分配吗?