SlideShare a Scribd company logo
C++ Question & Answer
91
C++ Question & Answer
92
C++ Question & Answer
93
4
1
1
0
0
1
0
0
1
1
94
46
1
95
The output would be as shown below. The 'a'
in "Titanic" has been changed to an 'i'.
Titinic
i
96
C++ Question & Answer
The nested conditional statement shown below has been
written by an inexperienced C/C++ programmer.
The behavior of the statement is not correctly represented
by the formatting
97
a. What is the output of the statement if the variable n has
the value 7 ? If n has the value 15 ? If n has the value -3 ?
b. Correct the syntax of the statement so that the logic of
the corrected statement corresponds to the formatting of the
original statement. Also, replace the blank with an appropriate word
or phrase.
c. Correct the formatting of the (original) statement so that
the new format reflects the logical behavior of the original
statement. Also, replace the blank with an appropriate word or phrase.
The original statement is formatted in such a
way that it appears that the "else" clause of the
statement
is the alternative to the "if (n < 10)" case, but in
fact, the C or C++ compiler will treat the "else"
clause as the alternative to the "if (n > 0)"
clause. If n has the value 7 , the output will be
"The
number is positive". If n has the value 15 , then
there will be no output. If n has the value -3
then the output will be "The number is
____________".
C++ Question & Answer
C++ Question & Answer
98
a. The output will be "less than 10".
b. The output will be "greater than 15".
c. The output will be "less than 10".
d. There is no value for n that will cause
the output to be "not interesting". That
part of the code can never be executed!
99
Rewrite the following code fragment so that it uses a
"do...while..." loop to accomplish the same task.
int n;
cout << "Enter a non-negative integer: ";
cin >> n;
while (n < 0)
{
cout << "The integer you entered is negative." << endl;
cout << "Enter a non-negative integer: ";
cin >> n;
}
C++ Question & Answer
100
What is the output when the following code
fragment is executed?
int n, k = 5;
n = (100 % k ? k + 1 : k - 1);
cout << "n = " << n << " k = " << k << endl;
NEXT
The output of the code fragment is as
follows:
n = 4 k = 5

More Related Content

DOCX
1 (1)
PDF
DOCX
New microsoft office word document
PDF
Prime number program in C
PPTX
C Programming Example
PDF
Progr3
PDF
Prime number program in c
PDF
C Programming Example
1 (1)
New microsoft office word document
Prime number program in C
C Programming Example
Progr3
Prime number program in c
C Programming Example

What's hot (16)

DOCX
Temp conversion
PDF
Bcsl 033 data and file structures lab s1-4
PDF
Bcsl 033 data and file structures lab s5-2
DOCX
Write a program to perform translation.
PDF
Bcsl 033 data and file structures lab s2-2
PDF
Bcsl 033 data and file structures lab s5-3
DOCX
Basic of c programming www.eakanchha.com
PPTX
C programming codes for the class assignment
PPT
comp1
DOCX
Dti2143 lab sheet 9
PDF
C mcq practice test 1
DOCX
Bti1022 lab sheet 9 10
DOCX
Write a program to perform translation
Temp conversion
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s5-2
Write a program to perform translation.
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s5-3
Basic of c programming www.eakanchha.com
C programming codes for the class assignment
comp1
Dti2143 lab sheet 9
C mcq practice test 1
Bti1022 lab sheet 9 10
Write a program to perform translation
Ad

Viewers also liked (8)

PDF
CCIA'2008: On the dimensions of data complexity through synthetic data sets
PDF
Lecture2 - Machine Learning
PPT
Artificail Intelligent lec-1
PDF
Lecture1 - Machine Learning
PDF
Lecture11 - neural networks
PPT
Mechanical element of a CNC Machine
PDF
Lecture1 AI1 Introduction to artificial intelligence
PPTX
Introduction to Machine Learning
CCIA'2008: On the dimensions of data complexity through synthetic data sets
Lecture2 - Machine Learning
Artificail Intelligent lec-1
Lecture1 - Machine Learning
Lecture11 - neural networks
Mechanical element of a CNC Machine
Lecture1 AI1 Introduction to artificial intelligence
Introduction to Machine Learning
Ad

Similar to C++ Question & Answer (20)

PDF
Solved Practice Problems For the C++ Exams
PDF
Practiceproblems(1)
PDF
C Programming Interview Questions
PDF
C101-PracticeProblems.pdf
PDF
CULEGERE INFORMATICA cu probleme rezolvate
PDF
Chapter 6 Balagurusamy Programming ANSI in c
PPT
DOC
Programming egs
DOC
C important questions
DOC
C operators
PDF
DOCX
C interview question answer 2
DOCX
C Control Statements.docx
PDF
CP Handout#5
PDF
C++ control structure
PDF
C programming
PDF
C faq pdf
PPTX
Cs1123 5 selection_if
PDF
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
PPTX
Najmul
Solved Practice Problems For the C++ Exams
Practiceproblems(1)
C Programming Interview Questions
C101-PracticeProblems.pdf
CULEGERE INFORMATICA cu probleme rezolvate
Chapter 6 Balagurusamy Programming ANSI in c
Programming egs
C important questions
C operators
C interview question answer 2
C Control Statements.docx
CP Handout#5
C++ control structure
C programming
C faq pdf
Cs1123 5 selection_if
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
Najmul

More from tjunicornfx (8)

PDF
PDF
AC in Vehicle -Sinhala note (Sri lanka) 1
PDF
AC in Vehicle -Sinhala note (Sri lanka) -3
PDF
AC in Vehicle -Sinhala note (Sri lanka) -2
PDF
Computer architecture for HNDIT
PPS
Procedures functions structures in VB.Net
PPT
Security architecture
PPT
04 introduction to computer networking
AC in Vehicle -Sinhala note (Sri lanka) 1
AC in Vehicle -Sinhala note (Sri lanka) -3
AC in Vehicle -Sinhala note (Sri lanka) -2
Computer architecture for HNDIT
Procedures functions structures in VB.Net
Security architecture
04 introduction to computer networking

Recently uploaded (20)

PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Classroom Observation Tools for Teachers
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Trump Administration's workforce development strategy
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Complications of Minimal Access Surgery at WLH
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
01-Introduction-to-Information-Management.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
master seminar digital applications in india
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Classroom Observation Tools for Teachers
STATICS OF THE RIGID BODIES Hibbelers.pdf
Trump Administration's workforce development strategy
Chinmaya Tiranga quiz Grand Finale.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
A systematic review of self-coping strategies used by university students to ...
Complications of Minimal Access Surgery at WLH
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Final Presentation General Medicine 03-08-2024.pptx
Yogi Goddess Pres Conference Studio Updates
01-Introduction-to-Information-Management.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
master seminar digital applications in india
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS

C++ Question & Answer

  • 2. 91
  • 4. 92
  • 6. 93
  • 8. 94
  • 10. 95
  • 11. The output would be as shown below. The 'a' in "Titanic" has been changed to an 'i'. Titinic i
  • 12. 96
  • 14. The nested conditional statement shown below has been written by an inexperienced C/C++ programmer. The behavior of the statement is not correctly represented by the formatting 97 a. What is the output of the statement if the variable n has the value 7 ? If n has the value 15 ? If n has the value -3 ? b. Correct the syntax of the statement so that the logic of the corrected statement corresponds to the formatting of the original statement. Also, replace the blank with an appropriate word or phrase. c. Correct the formatting of the (original) statement so that the new format reflects the logical behavior of the original statement. Also, replace the blank with an appropriate word or phrase.
  • 15. The original statement is formatted in such a way that it appears that the "else" clause of the statement is the alternative to the "if (n < 10)" case, but in fact, the C or C++ compiler will treat the "else" clause as the alternative to the "if (n > 0)" clause. If n has the value 7 , the output will be "The number is positive". If n has the value 15 , then there will be no output. If n has the value -3 then the output will be "The number is ____________".
  • 18. 98
  • 19. a. The output will be "less than 10". b. The output will be "greater than 15". c. The output will be "less than 10". d. There is no value for n that will cause the output to be "not interesting". That part of the code can never be executed!
  • 20. 99 Rewrite the following code fragment so that it uses a "do...while..." loop to accomplish the same task. int n; cout << "Enter a non-negative integer: "; cin >> n; while (n < 0) { cout << "The integer you entered is negative." << endl; cout << "Enter a non-negative integer: "; cin >> n; }
  • 22. 100 What is the output when the following code fragment is executed? int n, k = 5; n = (100 % k ? k + 1 : k - 1); cout << "n = " << n << " k = " << k << endl; NEXT
  • 23. The output of the code fragment is as follows: n = 4 k = 5