• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 4 pages
Exam (elaborations)

CSCI 240 - Quizzes 6 - 9 Questions And Answers Latest Updates

Document preview thumbnail
Preview 1 out of 4 pages

Write a C++ statement that takes the digit character in the char variable ch and changes it to its integer representation and saves the result in the integer variable intVal. So if ch contains '4', then intVal should contain the value 4. Assume that ch and intVal have been properly declared. - ️️intVal = ch - '0'; What will happen if a char is cout'd as an int? - ️️the ASCII value of the character will be displayed What is the ASCII value of the character '1'? - ️️49 What is the ASCII value of 'c'? - ️️99 Write a cout statement to display the ASCII value of the character stored in a char variable called ch. Assume that ch has been properly declared and contains a value. - ️️char ch; cout (int)ch; Explain what tolower() does to a character. The answer should include the argument(s) that are passed to tolower() (if any) and what it returns. - ️️tolower() takes a character that is passed Write a switch statement to print out a string depending on the value of a char variable called ch. If ~ ch is 'a' print "excellent" ~ ch is 'b' print "good" ~ ch is 'c' print "ok" ~ if ch is anything else, print "invalid" Assume that ch has been properly declared and contains a value. - ️️switch (ch) { case 'a': cout "excellent"; break; case 'b': cout "good"; break; case 'c': cout "ok"; break; default: cout "invalid"; } Declare an array named AR to hold 4 integers and fill it with the numbers 2, 4, 6, and 8. - ️️int AR[4] = { 2, 4, 6, 8};Assume an array called AR contains 4 integers. Write a loop to print out the values of the 4 integers. - ️️for ( int sub = 0; sub 4; sub++ ) { cout AR[sub]; } The data type char and the data type __________ are often interchageable in C++ - ️️int Assume an array called AR contains 4 integers. Write code to exchange the very first and the very last values in the array. - ️️int temp; temp = AR[0]; AR[0] = AR[3]; AR[3] = temp; Declare an array named AR to hold 1000 integers. In the declaration statement, initialize the array so the very first value is 10, the second is 20, and all the rest are 0. - ️️int AR[1000] = { 10, 20 }; Complete the following sentence: If you declare an array to hold N values, legal subscripts run from _____ to ______. - ️️0 to N - 1 Complete the following sentence: the unsubscripted name of an array is _______________________________. - ️️unsubscripted name of an array is the address of the array Write code to swap element [2] and element [4] in an array of floats called AR. Declare a simple variable called temp for this question, and assume the array is correctly declared and initialized. - ️️float temp; temp = AR[2]; AR[2] = AR[4]; AR[4] = temp; Write code to copy the 0th element of an array called AR into all the other elements of the array. Assume there are 10 elements in the array. - ️️for ( int sub = 1; sub = 10; sub++ ) { AR[sub] = AR[0]; } Complete the following sentence: all the elements of an array must be the same ____________. - ️️data type

Content preview

CSCI 240 - Quizzes 6 - 9
Write a C++ statement that takes the digit character in the char variable ch and changes
it to its integer representation and saves the result in the integer variable intVal. So if ch
contains '4', then intVal should contain the value 4. Assume that ch and intVal have
been properly declared. - ✔️✔️intVal = ch - '0';


What will happen if a char is cout'd as an int? - ✔️✔️the ASCII value of the character
will be displayed

What is the ASCII value of the character '1'? - ✔️✔️49

What is the ASCII value of 'c'? - ✔️✔️99

Write a cout statement to display the ASCII value of the character stored in a char
variable called ch. Assume that ch has been properly declared and contains a value. -
✔️✔️char ch;
cout << (int)ch;

Explain what tolower() does to a character. The answer should include the argument(s)
that are passed to tolower() (if any) and what it returns. - ✔️✔️tolower() takes a
character that is passed


Write a switch statement to print out a string depending on the value of a char variable
called ch. If
~ ch is 'a' print "excellent"
~ ch is 'b' print "good"
~ ch is 'c' print "ok"
~ if ch is anything else, print "invalid"
Assume that ch has been properly declared and contains a value. - ✔️✔️switch (ch)
{
case 'a': cout << "excellent";
break;
case 'b': cout << "good";
break;
case 'c': cout << "ok";
break;
default: cout << "invalid";
}

Declare an array named AR to hold 4 integers and fill it with the numbers 2, 4, 6, and 8.
- ✔️✔️int AR[4] = { 2, 4, 6, 8};

Document information

Uploaded on
October 10, 2024
Number of pages
4
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$8.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ACADEMICMATERIALS
4.0
(100)
Sold
625
Followers
185
Items
10510
Last sold
2 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions