在C++程序中实现软件测试的边界值分析
Implementing Boundary Value Analysis of Software Testing in a C++ program?
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int n,a[n],x,c,u[n],m[n],e[n][4];
cout<<"Enter the number of variables";
cin>>n;
cout<<"Enter the Lower, and Upper Limits of the variables";
for(int y=1; y<n+1; y++)
{
cin>>m[y];
cin>>u[y];
}
for(x=1; x<n+1; x++)
{
a[x] = (m[x] + u[x])/2;
}
c=(n*4)-4;
for(int a1=1; a1<n+1; a1++)
{
e[a1][0] = m[a1];
e[a1][1] = m[a1]+1;
e[a1][2] = u[a1]-1;
e[a1][3] = u[a1];
}
for(int i=1; i<n+1; i++)
{
for(int l=1; l<=i; l++)
{
if(l!=1)
{
cout<<a[l]<<"t";
}
}
for(int j=0; j<4; j++)
{
cout<<e[i][j];
for(int k=0; k<n-(i+1); k++)
{
cout<<a[k]<<"t";
}
cout<<"n";
}
}
system("PAUSE");
return 0;
}
答案应该以表格的形式出现,例如
1 50 50
2 50 50
99 50 50
100 50 50
50 1 50
50 2 50
50 99 50
50 100 50
50 50 1
50 50 2
50 50 99
50 50 100
如果输入数为 3,其范围为1,1001,1001,100(也可以变化(
输出没有来,任何人都可以纠正代码或告诉我出了什么问题吗?
我不会深入研究您的代码,但我可以指出您的代码中的一些错误:
int n,a[n],x,c,u[n],m[n],e[n][4];
- 这些数组(
- 其大小为局部值(称为 VLA(可变长度数组(,是 C++ 的扩展。不要使用它们。
- 在数组的声明中,
int n
尚未初始化(它来自两行后的用户输入(。因此,所有这些数组的大小都无效。
for(int y=1; y<n+1; y++)
- 对于大小为
n
的数组,有效索引的范围从0
到n-1
。
system("PAUSE");
- 这是特定于平台的,在某些情况下可能会很烦人。更喜欢要求用
std::cin
击键。
一般来说,如果你使用的是C++,你应该放弃使用老式的C数组。更喜欢标准库为您提供的漂亮数据结构,例如 std::vector
、 std::list
、 std::deque
或 C++11 std::array
。
希望有帮助。
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int n,a[3],x,c,max[3],min[3],e[3][4];
cout<<"Enter the number of variables";
cin>>n;
cout<<"Enter the minimun, and maximun Limits of the variables";
for(int y=0; y<n; y++)
{
cin>>min[y];
cin>>max[y];
}
for(x=0; x<n; x++)
{
a[x] = (min[x] + max[x])/2;
}
for(int a1=0; a1<n; a1++)
{
e[a1][0] = min[a1];
e[a1][1] = min[a1]+1;
e[a1][3] = max[a1]-1;
e[a1][4] = max[a1];
}
for(int i=0; i<n; i++)
{
for(int j=0; j<4; j++)
{
for(int l=1; l<=i+1; l++)
{
if(l!=1)
{
cout<<a[2]<<"t";
}
}
cout<<e[i][j]<<"t";
for(int k=0; k<n-(i+1); k++)
{
cout<<a[k]<<"t";
}
cout<<"n";
}
}
system("PAUSE");
return 0;
}
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 尽管测试成功,CppUnit测试核心仍被丢弃.为什么
- 数据成员SFINAE的C++17测试:gcc vs clang
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么二进制搜索在我的测试中不起作用
- 从父数组测试用例构造二叉树失败
- std::当在256字节边界上写入整数时,流的奇怪行为
- 试图对缓存进行跨步测试,但程序并没有结束
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- OpenGL在启用深度测试时不会丢弃我的碎片
- 为测试目标创建具有不同源文件夹的文件
- 在子目录中使用target_sources()命令时用于单元测试(qtest)的项目结构
- VC++本机单元测试,找不到调试符号
- 换位表导致测试失败(但在游戏中运行良好)
- 这是针对大学中期100级软件类的合理书面测试
- 软件定义无线电 USRP X310 的测试程序
- 如何在cocos2d-x3测试版中围绕精灵绘制边界框
- 测试操作系统性能时,硬件开销和软件开销有什么区别
- 在C++程序中实现软件测试的边界值分析