在C++程序中实现软件测试的边界值分析

Implementing Boundary Value Analysis of Software Testing in a C++ program?

本文关键字:边界 软件测试 C++ 程序 实现      更新时间:2023-10-16
#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 的数组,有效索引的范围从 0n-1

system("PAUSE");

  • 这是特定于平台的,在某些情况下可能会很烦人。更喜欢要求用std::cin击键。

一般来说,如果你使用的是C++,你应该放弃使用老式的C数组。更喜欢标准库为您提供的漂亮数据结构,例如 std::vectorstd::liststd::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;    
}