I am participating in few online programming exercises in C++.
Here problem description is given as to test understanding "for" loop in C++.
Input Format
You will be given two positive integers, a and b (a <=b), separated by a newline.
Output Format
For each integer in the interval [a,b :
If 1 <=n <= 9, then print the English representation of it in lowercase. That is "one" for , "two" for , and so on. Else if n > 9 and it is an even number, then print "even". Else if n > 9 and it is an odd number, then print "odd".
Sample Input
8 11
Sample Output
eight
nine
even
odd
I have written program as below and test case passed.
int main() {
int a, b;
cin >> a;
cin >> b;
string num[9] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
for(int n=a; n<=b;n++)
{
if(n<=9)
cout << num[n-1] << endl;
else
if(n%2==0)
cout << "even\n";
else
cout << "odd\n";
}
return 0;
}
While I am testing, I am entering values for "a" and "b".
I can understand when I submit my code online, test cases are executed and results are shown.
My question how input is automated?. I also want to test my code with automation with out entering input at console.
Sample code for automate will be helpful. This understanding will be helpful as I move forward in working on complex problems where more inputs will be required, so I don't want to enter manually at cin from console and want to automate this while i am testing at my laptop, just same as the way online automated test tool is doing.
Thanks for your time and help.
Aucun commentaire:
Enregistrer un commentaire