Академический Документы
Профессиональный Документы
Культура Документы
Assignment two
Question One
1. Write a program to implement the concept of while, for,
dowhile, switch and ifelse and prepare test cases,
expected output and compare it with the actual output.
I. While loop
//Program that can display n to 5 numbers
//where n is -5 to 5
#include <iostream>
using namespace std;
int main () {
int num;
cout<<"Enter a number"<<endl;
cin>>num;
cout<<"values : ";
while( num <=5 ) {
cout << num << ",";
num++;
}
return 0;
}
Different number of test cases expected outcome and
compare it with actual outcomes for while loop
Character
input
return 0;
}
Character
input
III. if else
//Program that can display 0 to 5 numbers
#include <iostream>
using namespace std;
int main(){
int mark;
cout << "What mark did you get in the test?" << endl;
cin >> mark;
return 0;
}
Different number of test cases expected outcome and
compare it with actual outcomes for ifelse statement
int main () {
char grade;
cout<<"Enter a Letter A -to - D"<<endl;
cin >>grade;
switch(grade) {
case 'A' :
cout << "Excellent!" << endl;
break;
case 'B' :
case 'C' :
cout << "Well done" << endl;
break;
case 'D' :
cout << "You passed" << endl;
break;
case 'F' :
cout << "Better try again" << endl;
break;
default :
cout << "Invalid grade" << endl;
}
return 0;
}
Different number of test cases expected outcome and
compare it with actual outcomes for switch case.
V. For loop
//Program that can display n to 5 numbers using for loop
#include <iostream>
using namespace std;
int main () {
int num;
cout<<"Enter a number"<<endl;
cin>>num;
cout<<"values : ";
for(int j=num; j <=5; j++ )
{
cout << j << ",";
}
return 0;
}
Different number of test cases expected outcome and
compare it with actual outcomes for For loop
Question two
2. Consider a program for the determination of the nature of
roots of a quadratic equation. Its input is a triple of
positive integers (say a, b, c) and values may be from
interval [0,100]. The program output may have one of the
following words. [Not a quadratic equation; Real roots;
Imaginary roots; Equal roots] Design the boundary value
test cases.
Solution:
This program is for the determination of the nature of roots of a
quadratic equation. Its input is a triple of positive integers (Say
a, b, c) and values may be from interval [0, 100]. The program
output may have one of the following words as given on the
question.
type: ax2 + bx + c = 0