Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can someone do this for me ? Exercises At the end of each chapter, we include ex

ID: 3742240 • Letter: C

Question

can someone do this for me ?

Exercises

At the end of each chapter, we include exercises you can do with the things you've learned. We encourage you to at least attempt every problem. You can't learn to program only by reading about it; you have to practice.

Before you can compile and run C++ programs, you might have to download and install a few tools. There are many good options. We recommend either Visual Studio Community 2017 if you are working in the Windows operating system or Code::Blocks for all operating systems. Instructions for installing these programming environments are in Appendix A.

The code for this chapter is in the ch01 directory of ThinkCPPCode. See "Using the Code Examples" on page xx for instructions on how to download the repository. Before you start the exercises, we recommend that you compile and run the examples.

Exercise 1-1.

Computer scientists have the annoying habit of using common English words to mean something other than their common English meaning. For exampe, in English, statements and comments are the same thing, but in programs they are different.

In computer jargon, what is the difference between a statement and a comment?

What does it mean to say that a program is portable?

In common English, what does the word compile mean?

What is an executable? Why is that word used as a noun?

The glossary at the end of each chapter is intended to highlight words and phrases that have special meanings in computer science. When you see familiar words, don't assume that you know what they mean!

Exercise 1-2.

Before you do anything else, find out how to compile and run a C++ program. Some environments provide sample programs similar to the example in "The Hello World! Program" on page x.

Type in the hello world program, then compile and run it.

Add an output statement that displays a second message after the "Hello, World!". Say something witty like, "How are you?" Compile and run the program again.

Add a comment to the program (anywhere), recompile, and run it again. The new comment should not affect the result.

This exercise may seem trivial, but it is the starting place for many of the programs we will work with. To debug with confidence, you will need to have confidence in your programming environment.

In some environments, it is easy to lose track of which program is executing. You might find yourself trying to debug one program while you are accidentally running another. Adding (and changing) output statements is a simple way to be sure that the program you are looking at is the program you are running.

Exercise 1-3.

It is a good idea to commit as many errors as you can think of, so that you see what error messages the compiler produces. Sometimes the compiler tells you exactly what is wrong, and all you have to do is fix it. But sometimes the error messages are misleading. Over time you will develop a sense for when you can trust the compiler and when you have to figure things out yourself.

Starting with the hello world program, try out each of the following errors. After you make each change, compile the program, read the error message (if there is one), and then fix the error.

Remove one of the open curly braces.

Remove one of the close curly braces.

Instead of main, write mian.

Remove the word int.

Remove the word main.

Replace cout with Cout.

Remove the <<. Add an extra one << <<

Explanation / Answer

Exercise 1-1
(1) In Computer jargon, Statements are the defined steps which are executed and carried out to get the desired output/result of a computer program.
as e.g. In C++
cout<<"Hello World";
this is an example of a statement in C++. They generally end with a semicolon (;).
While a comments are the explanatory statements which help to increase the readability of the code, i.e. telling someone the use of any statement in the program.
as e.g. in C++
A statement can be written as using "//" (for single line comment) and "/* */" for multi line comment.
Writing comment doesn't have an impact on the output of a computer program.
cout<<"Hello World";   //This is a print statement
(2) A program is called portable if it can run on any other operating system/environment other than on which it is made or we can generalise this aa a program which can easily be moved from one system to another system and it can work as it supposed to be on the other system with different opearting system / hardware/ environment.
(3) In Common English, Compile means the accumulation of information from multiple sources to one source/one place.
(4) An executable can be seen as a program which carries out a specific task/set of tasks. This is considered as a noun since it shows us the class of programs which can be executed.
Exercise 1-2

(1) Hello world program
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello, World!";
return 0;
}
-----------OUTPUT------------
Hello, World!

(2)
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello, World!";
cout<<"How are you?";
return 0;
}
-------------------OUTPUT-------------------
Hello, World!How are you?

(3)
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello, World!"; //First CPP Program
cout<<"How are you?";
return 0;
}
-------------------OUTPUT-------------------
Hello, World!How are you?

Exercise 1-3

(1) Remove one of the open curly braces
#include<iostream>
using namespace std;
int main()
cout<<"Hello, World!"; //First CPP Program
cout<<"How are you?";
return 0;
}
--------------ERROR-------------
4 errors
expected initializer before 'cout'
'cout' does not name a type
expected unqualified-id before 'return'
expected declaration before '}' token.

We can easily remove the error by adding the open curly braces again.

(2) Remove one of the close curly braces.
#include<iostream>
using namespace std;
{
int main()
cout<<"Hello, World!"; //First CPP Program
cout<<"How are you?";
return 0;

--------------ERROR-------------
1 error
expected '}' at end of input.

We can easily remove the error by adding the close curly braces again.

(3) Instead of main, write mian.
#include<iostream>
using namespace std;
{
int mian()
cout<<"Hello, World!"; //First CPP Program
cout<<"How are you?";
return 0;
}
--------------ERROR-------------
2 errors
undefined reference to 'main'.
ld returned 1 exit status.

We can easily remove the error by typing main instead of mian.

(4) Remove the word int.
#include<iostream>
using namespace std;
{
main()
cout<<"Hello, World!"; //First CPP Program
cout<<"How are you?";
return 0;
}
--------------ERROR-------------
there will be no error.( In some compiler it might show a warning)


(5) Remove the word main.
#include<iostream>
using namespace std;
{
int
cout<<"Hello, World!"; //First CPP Program
cout<<"How are you?";
return 0;
}
--------------ERROR-------------
1 error
expected unqualified-id before '{' token.

We can easily remove the error adding main.

(6) Replace cout with Cout.
#include<iostream>
using namespace std;
{
int main();
Cout<<"Hello, World!"; //First CPP Program
Cout<<"How are you?";
return 0;
}
--------------ERROR-------------
1 error
'Cout' was not declared in this scope.

We can easily remove the error by replacing cout with Cout.


(7) Remove the <<
#include<iostream>
using namespace std;
{
int main();
cout"Hello, World!"; //First CPP Program
cout"How are you?";
return 0;
}
--------------ERROR-------------
2 errors
expected ';' before string constant.
expected ';' before string constant.

We can easily remove the error by adding "<<" again.

(8) Add an extra one << <<
#include<iostream>
using namespace std;
{
int main();
cout<<<<"Hello, World!"; //First CPP Program
cout<<<<"How are you?";
return 0;
}
--------------ERROR-------------
2 errors
expected primary-expression before '<<' token.
expected primary-expression before '<<' token.

We can easily remove the error by removing extra "<<".

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote