Interleaved input / output (C++) Auto-graded programming assignments have numero
ID: 3722094 • Letter: I
Question
Interleaved input / output (C++)
Auto-graded programming assignments have numerous advantages, but have some challenges too. Students commonly struggle with realizing that example input / output provided in an assignment's specification interleaves input and output, but the program should only output the output parts. If a program should double its input, an instructor might provide this example:
Students often incorrectly create a program that outputs the 5. Instead, the program should only output the output parts:
The instructor's example is showing both the output of the program, AND the user's input to that program, assuming the program is developed in an environment where a user is interacting with a program. But the program itself doesn't output the 5 (or the newline following the 5, which occurs when the user types 5 and presses enter).
Also, if the instructor configured the test cases to observe whitespace, then according to the above example, the program should output a newline after Enter x: (and possibly after the 25, if the instructor's test case expects that).
The program below incorrectly echoes the user's input to the output.
Try submitting it for grading (click "Submit mode", then "Submit for grading"). Notice that the test cases fail. The first test case's highlighting indicates that output 3 and newline were not expected. In the second test case, the -5 and newline were not expected.
Remove the code that echoes the user's input back to the output, and submit again. Now the test cases should all pass.
#include <iostream>
using namespace std;
int main() {
int x;
cout << "Enter x: " << endl;
cin >> x;
cout << x << endl; // Student mistakenly is echo'ing the input to output to match example
cout << "x doubled is: " << 2 * x << endl;
return 0;
}
Explanation / Answer
I am not very sure about the program process and what you are looking for. As far my understanding program should not outputted value and new line.
So made few changes to the above program. Could you please have a look and let me know in comments your feedback.
#include <iostream>
using namespace std;
int main() {
int x;
cout << "Enter x: " << endl;
cin >> x;
cout << "x doubled is: " << 2*x<< endl;
return 0;
}
Enter X
5
X doubled is 10.
#include <iostream>
using namespace std;
int main() {
int x;
cout << "Enter x: " << endl;
cin >> x;
cout << "x doubled is: " << 2*x<< endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.