Professional Documents
Culture Documents
Assignment No. 1
(By : Richard L. Halterman)___________
Name:
Shakeel Zafar
Class:
Bachelor of Electrical Engineering
. (1st semester)
Roll No:
FA19-BEE-083
Section:
C
Date:
15.01.2020
EXERCISE#1
Question.1:
What is a compiler?
Answer:
Question.2:
Answer:
Question.3:
Answer:
Question.4:
Answer:
A programmer uses preprocessor to change source code into
enhanced source code, then he uses compiler to translate it to object
code and then he uses linker to convert it to executable machine code.
Question.5:
Answer:
Question.6:
Answer:
Question.7:
Answer:
Answer:
Question.9:
How can an IDE improve a programmers’s productivity?
Answer:
An IDE, or Integrated Development Environment, enables
programmers to consolidate the different aspects of writing a computer
program. IDEs increase programmer productivity by combining common
activities of writing software into a single application: editing source code,
building executables, and debugging.
Question.10:
Name a popular a C++ IDE used by programmers for developing
Microsoft Windows.
Answer.10;
1. Eclipse. It is one of the most popular, powerful and useful IDEs used by
developers for C/C++ programming. ...
2. NetBeans. ...
3. Visual Studio Code. It is an open-source code editor developed Sublime Text. ...
4. Atom. ...
5. Code::Blocks. ...
6. CodeLite. ...
7. CodeWarrior.
Question.11
Name a popular a C++ IDE used by programmers for developing Apple
MacOS.
Answer,11:
0. Eclipse is one of the simplest and most powerful IDEs for
C++ development. This is an open source IDE that is available for
Windows, Mac OS X, and Linux
1. Visual Studio Code. Visual Studio Code is possibly the best JavaScript ide for
Windows, Mac, and Linux. ...
2. RJ TextEd. ...
3. Light Table. ...
4. NetBeans. ...
5. Brackets. ...
6. Komodo Edit. ...
7. Atom by Github. ...
8. SUBLIME TEXT 3.
EXERCISE#2
Question.1:
Answer:
When a cout statement executes, it sends a stream of
characters to the standard output stream object - std::cout - which is
normally “connected” to the screen. The std::
before cout is required when we use names that we've brought into the
program by the preprocessing directive #include <iostream>.
Question.2:
Answer:
Question.3:
Answer:
Question.4:
Answer:
Question.5:
Answer:
Question.6:
Answer:
Question.7:
Answer:
#include <iostream>
int main() {
<< “Shakeel!\n”
IN CONSOLE WINDOW
Hello User, Enter your first name.
Shakeel
Hello Shakeel, It was nice to know your name!
Question.8:
Write a C++ program that prints your first and last name in
the console window. Your first name should appear on one line, and your
last name on the next line.
Answer:
#include <iostream>
int main() {
IN CONSOLE WINDOW
Input First Name: Shakeel
Input Last Name: Zafar
Question.10:
Answer:
Question.1:
Will the following lines of code print the same thing? Explain why
or why not.
std::cout << 6 << '\n';
std::cout << "6" << '\n';
Answer:
Yes, they will print the same thing ,since 6 has no character type
assigned to it in ASCII system.
Question.2:
Will the following lines of code print the same thing? Explain why
or why not.
std::cout << x << '\n';
std::cout << "x" << '\n';
Answer:
Question.3:
Answer:
Answer:
Question.5:
Answer:
Question.6:
Answer:
Question.7:
Answer:
Answer:
Question.9:
Answer:
Question.10:
Once a variable has been properly declared and initialized can its
value be changed?
Answer:
Answer:
1. #include <iostream>
2. int main() {
3. int x{10};
4. std::cout << x << '\n';
5. }
This alternate form is not commonly used for simple variables, but it
necessary for initializing more complicated
kinds of variables called objects.
Question.12:
In C++ can you declare more than one variable in the same
declaration statement? If so, ow?
Answer:
Question.13:
In the declaration
int a;
int b;
Answer:
int a;
int b;
does not mean a and b refer to the same box (memory location).
Question.14:
Answer:
(a) fred Legal
(b) if Illegal
(c) 2x Illegal
(d) -4 Illegal
(e) sum_total Legal
(f) sumTotal Legal
(g) sum-total Illegal
(h) sum total Illegal
(i) sumtotal Legal
(j) While Legal
(k) x2 Legal
(l) Private Legal
(m) public Illegal
(n) $16 Illegal
(o) xTwo Legal
(p) _static llegal
(q) _4 llegal
(r) _ _ _ llegal
(s) 10% Illegal
(t) a27834 Legal
(u) wilma's Illegal
Question.15:
What can you do if a variable name you would like to use is the
same as a reserved word?
Answer:
Question.16:
Question.17:
Answer:
Question.18:
Answer:
Answer:
It is expressed as 2.45e-5.
Question.20:
Question.21:
Answer:
We can increase the range of int by adding longh and long long
before int like:
long int;
Question.22:
How can you extend the range and precision of double on some
systems?
Answer:
long double;
Write a program that prints the ASCII chart for all the values from
0 to 127.
Answer:
1. /*
2. * C++ Program to Print ASCII table (0 - 127)
3. */
4.
5. #include<iostream>
6. #include<iomanip>
7. using namespace std;
8.
9. char const* character[] = {"", "", "", "", "", "", "", "",
10. "\\a","\\b","\\t","\\n","\\v","\\f","\\r", "",
11. "", "", "", "", "", "", "", "",
12. "", "", "", "", "", "", "", ""};
13.
14. int main()
15. {
16. char c;
17. int row;
18. cout << " ASCII Table" << endl << "=============" << endl;
19. for(int i = 0; i < 16; i++)
20. {
21. row = i;
22. while (row <= 127) {
23. if (row < 32)
24. cout << setfill('0') << setw(2) << setbase(16)
25. << row << " = " << setw(3) << setfill(' ')
26. << character[i] << " | ";
27. else if (row >= 32 && row < 127)
28. {
29. c = row;
30. cout << setfill('0') << setw(2) << setbase(16)
31. << row << " = " << setw(3) << setfill(' ')
32. << c << " | ";
33. }
34. else
35. cout << setfill('0') << setw(2) << setbase(16)
36. << row << " = " << setw(3) << setfill(' ')
37. << "DEL" << " | ";
38. row = row + 16;
39. }
40. cout << endl;
41. }
42. }
43. cout << "!" << endl;
44. }
ASCII Table
=============
00 = | 10 = | 20 = | 30 = 0 | 40 = @ | 50 = P | 60 = ` | 70 = p
|
01 = | 11 = | 21 = ! | 31 = 1 | 41 = A | 51 = Q | 61 = a | 71 = q
|
02 = | 12 = | 22 = " | 32 = 2 | 42 = B | 52 = R | 62 = b | 72 = r
|
03 = | 13 = | 23 = # | 33 = 3 | 43 = C | 53 = S | 63 = c | 73 = s
|
04 = | 14 = | 24 = $ | 34 = 4 | 44 = D | 54 = T | 64 = d | 74 = t
|
05 = | 15 = | 25 = % | 35 = 5 | 45 = E | 55 = U | 65 = e | 75 = u
|
06 = | 16 = | 26 = & | 36 = 6 | 46 = F | 56 = V | 66 = f | 76 = v
|
07 = | 17 = | 27 = ' | 37 = 7 | 47 = G | 57 = W | 67 = g | 77 = w
|
08 = \a | 18 = \a | 28 = ( | 38 = 8 | 48 = H | 58 = X | 68 = h | 78 = x
|
09 = \b | 19 = \b | 29 = ) | 39 = 9 | 49 = I | 59 = Y | 69 = i | 79 = y
|
0a = \t | 1a = \t | 2a = * | 3a = : | 4a = J | 5a = Z | 6a = j | 7a = z
|
0b = \n | 1b = \n | 2b = + | 3b = ; | 4b = K | 5b = [ | 6b = k | 7b = {
|
0c = \v | 1c = \v | 2c = , | 3c = < | 4c = L | 5c = \ | 6c = l | 7c = |
|
0d = \f | 1d = \f | 2d = - | 3d = = | 4d = M | 5d = ] | 6d = m | 7d = }
|
0e = \r | 1e = \r | 2e = . | 3e = > | 4e = N | 5e = ^ | 6e = n | 7e = ~
|
0f = | 1f = | 2f = / | 3f = ? | 4f = O | 5f = _ | 6f = o | 7f = DEL
|
Question.24:
Answer:
It is a string literal.
Question.25:
Answer:
It is a character literal.
Question.26:
Answer:
Question.27:
Answer:
If the character is from the ASCII system, then we can assign int
value to char value according to the ASCII system.
Question.28:
What is printed by the following code fragment?
int x;
x = 'A';
std::cout << x << '\n';
Answer:
Question.29:
Answer:
Question.30:
Write a C++ program that simply emits a beep sound when run.
Answer:
1. #include <iostream>
2. #include <windows.h> // WinApi header
3.
4. using namespace std;
5.
6. int main()
7. {
8. Beep(523,500); // 523 hertz (C5) for 500 milliseconds
9. cin.get(); // wait
10. }
Question.31:
1. #include <iostream>
2. using namespace std;
3.
4. // Define the enum data type Days
5. enum Days
6. {
7. monday, //monday = 0 by default
8. tuesday = 0,//tuesday = 0 also
9. wednesday, //wednesday = 1
10. thursday, //thursday = 2
11. friday, //and so on.
12. saturday,
13. sunday
14. };
Question.35:
Answer:
CHAPTER NO 4
Q1: Is the literal 4 a valid C++ expression?
Answer:-
No,
An expression is the one which involves any arithmetic
operators. Since no operator has been used with 4, so it is an
invalid expression.
Answer:-
No,
An expression is the one which involves any arithmetic
operators. Since no operator has been used with x, so it is an
invalid expression.
Q3. Is x + 4 a valid C++ expression?
Answer:-
Yes, It is a valid expression.
Answer:-
It has no effect on a numeric expression.
Answer:-
( *> / >% >+> - > = )