C++ Programmin. Please help. First part : using cout ----------------------- alw
ID: 3883397 • Letter: C
Question
C++ Programmin. Please help.
First part : using cout
-----------------------
always include at the top of a code-block a display like:
// ****** First part ******
cout << "Output displayed using cout ";
USE A SIMILAR HEADER FOR ALL FOLLOWING SECTIONS.
SEE ATTACHMENT AS AN OUTPUT-STYLE EXAMPLE.
25. 25. For the first part, implement the source code to display an
output as
1 2 3 4
using cout, endl, , in the following consecutive versions:
1 – using one ‘cout‘ statement, with the numbers as one string;
2 - using one ‘cout‘ statement, with four cascaded string-inputs;
3 - repeat, using integer numbers as four inputs (you must insert
spaces as " ";
4 - repeat, using characters;
5 - using four individual ‘cout’ statements, and using only one
string at a time (insert space-separator in every string).
26. Implement the above versions one at a time:
- permanently watch the ‘Error List’, and fix the code flagged
by IntelliSense;
- save the source-file from time to time by using ‘Save All’;
- build and run one version at a time.
27. At the end of this first part, and also at the end of all
following sections, pause using:
system("pause"); // it displays: Hit any key to continue
system("cls");
Capture the output-screen
-------------------------
28. Capture the output in a file, give it a name, and save it in your
solution-folder.
Follow the Handout instructions.
And do it after every new section that follows.
Second part : using ‘printf_s()’
--------------------------------
29. Use ‘printf_s()’ instead of cout’, for all above implementation
versions.
Before you start adding the new code, comment out the code
already implemented for ‘cout’, using the preprocessor directives
#if and #endif.
And do the same thing for all sections to be implemented next.
In the end, de-activate the two preprocessor-directives using
// in front of them, to run all implemented-sections, from the
top to the end of the project-source-code.
Here are some implementation-examples for this second ‘printf’
section:
printf("%d %d ", 1, 2); // space inside the control-string
printf("%s%s ", "1 ", "2 "); // space inside the
// displayable strings
You may also use
scanf_s("%c", &ch, 1); // to insert a “pause”
instead of system("pause");
Note: the old version scanf_s("%c", &ch) is no longer recommended.
Try it. You get an warning: not enough arguments passed.
Third part : display a table
----------------------------
30. Implement a source code, using ‘cout’, to display the table:
number square cube
1 1 1
2 4 8
3 9 27
with columns displayed at a TAB distance ( ):
- declare an ‘int’ variable ‘n’, initialized to 1;
- using operators ++ and * to move ‘n’ from 1 to 27
- from 1 to 2, use n++
- from 2 to 4, use n*n
- and so on.
Note: the ‘cube’ column doesn’t display the values right-justified.
Fourth part : display a triangle
--------------------------------
31. Display a triangle using ‘cout’ with only one input-string:
*
**
***
****
*****
Fifth part : display a rectangle
--------------------------------
32. Implement a source code, using ‘cout’, to display a rectangle:
^ ------------------
| | |
a | |
| | |
v ------------------
<--------b------->
Output example:
eIcome to C+ utput displayed using cout Inplenent code to display the output as -using e cout' statenent. with the numbers as one string 2-using one statement with four cascaded string-inputs 11 3 23 -repeat, using integer numbers as four inputs 1-repcat, using character:3 s as one string "; 1 2 3 1 using four individual cout' statenents using only one string at a tine 2 3 ng-inputs In" Press any key to continue-.. _ coutExplanation / Answer
#include<iostream>
using namespace std;
int main(){
//30
int n=1;
cout<<"number square cube"<<endl;
for(int i=0;i<3;i++){
cout<<n<<" "<<n*n<<" "<<n*n*n<<endl;
n++;
}
return 0;
}
//31
#include<iostream>
using namespace std;
int main(){
//31
char a[100] = "*";
for(int i=1;i<=5;i++){
for(int j=0;j<i;j++){
cout<<a;
}
cout<<endl;
}
return 0;
}
//32
#include<iostream>
using namespace std;
int main(){
//32
cout<<"^ ------------------"<<endl;
cout<<"| | |"<<endl;
cout<<"a | |"<<endl;
cout<<"| | |"<<endl;
cout<<"v ------------------"<<endl;
cout<<"<--------b------->"<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.