Max Value-Unit test

Source: Internet
Author: User

Design ideas

When debugging, as much as possible to take into account all possible situations, enter these conditions, to see the results of the program running

Source

#include <iostream>

using namespace Std;

int largest (int list[], int length);

int main ()

{

int list[100];

int lenght;

int i;

cout << "Please enter the length of the one-dimensional array:";

Cin >> Lenght;

if (lenght = = 0)

{

Cerr << "Array length cannot be zero!! "<< Endl;

return 0;

}

cout << "Please enter" << lenght << "integer:";

for (i = 0; i < lenght; i++)

{

CIN >> List[i];

}

cout << "The maximum value of this array is:" << largest (list, lenght) << Endl;

return 0;

}

int largest (int list[], int length)

{

int i, max=list[0];

for (i = 1; i < length; i++)

{

if (List[i] > Max)

{

max = List[i];

}

}

return Max;

}

Test

Issues found

Array length input is the character is the program error, also cannot be a floating-point number, negative, such as non-0 natural numbers;

The numbers in the array are calculated by the integer portion of the input floating-point number when the float is entered;

When Max's initial value is set to List "0", the value of I can start at 1;

Summarize

To treat each procedure with a special and rigorous attitude;

Should keep in mind that the computer is dead, and people are alive, the program is possible, can not let go of any detail!

Max Value-Unit test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.