Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am learning c++. I am using C++ from control structures through objects by Tony Gaddis book. Can yo help me? Chapter 10: Characters, C-Strings,

I am learning c++. I am using C++ from control structures through objects by Tony Gaddis book. Can yo help me?

Chapter 10: Characters, C-Strings, and More About the string Class

Independent Study

This assignment will be graded on the basis of completion and effort.

Place your answer on the line below each question and highlight the answer.

When a program is required, print the code and screenshot according to directions and attach the printouts in order to the back. When grading, points are possible.

Sections 10.1-10.2 (Pages 547-554)

1. On the computer:

(5 pts) Write a program called Checkinput,that asks the user to input a value that represents weeks. Calculate and display the number of days in those weeks. Ask the user if he/she wants to input another value to be calculated. Validate the input (converting the input to upper case in the trap) and write the code that will allow for another input (again converting the input to upper case). (See example Program 10.3)

Sections 10.3-10.4 (Pages 554-558)

2. (1 pt) The two primary ways that strings are stored in memory are string objects (using the string class as we have already) and C-strings. Explain how C-strings (string literals) are stored.

3. (1 pt) const int SIZE = 10;

char food [SIZE};

cin >>food;

Considering the code above, draw the memory location that would store an input of pizza. You can insert a table and fill in the data.

4. (1 pt) Referring to question #3 above, rewrite the line that will ensure that the user does not input a word that will write past the end of the array.

5. (1 pt) With this new code in #4, how many characters will the computer allow to be input?

6. On the computer:

(12 pts) Write a program called CountElements that does the following:

Declare a char array called sentence of 40 elements and assign the following: (I have noted the spacing)

How(sp)is(sp)Course(sp)1,(sp)C++,(sp)going(sp)4(sp)u?

Declare counters that will count the number of elements that are:

alphabetic, digits, upper case, lower case, punctuation and spaces

(ex: numalph=0, numdig=0, etc)

Loop through each character in the array and increase the proper counter.

Write the lines to determine each of the outputs.

Output: alphabet letters:

digits:

etc.

See the while loop on page557 and 558 (ex: while (sentence [count] != \0))

Run the program. Print the code and a screenshot. See the sample output on the next page.

Output:

alphabet letters: 18

digits: 2

upper case: 3

lower case: 15

spaces: 7

punctuation: 5

Press any key to continue . . .

7. (20 pts total) On the computer: Write a program named StringStuff. See pages 558-566. Declare strings of your choosing (not those used in the book).

Demonstrate the following functions by first listing and defining the function (1/2 pt each), write an explanation of how you are using the function, then writing code (2pt each) that performs that function:

strlen

strcat

strcpy

strncat

strncpy

strstr

strcmp

using ! with strcmp

Sample output: Strlen returns the length of

The length of the string happiness is:

0r

(explain concatenate)

When the string ----- is concatenated with the string --- the result is ---.

Assign the strings into memory; do not ask the user for them.

6. (4 pts)Do Page 568 Checkpoint: 10.7-10.10.

Section 10.5

7. (6 pts) Do Page 574 Checkpoint 10.11-10.15

Section 10.6

8. (1 pt)Read the text pages 575-580. Do Page 580: Checkpoint 10.16

Section 10.7 : More About the C++ string Class

9. (3 pts) On the computer: Following the directions in #7 above, write a program named MoreStrings that demonstrates the following concepts:

comparing and sorting strings (ask for 2 words then alphabetize)

+= (appending) (ask for 2 words then demonstrate append)

+ (concatenating 2 strings) (ask for 2 words then demonstrate concatenate)

Run the program. Print the code and a screenshot.

Review Questions and Exercises Page 594

10. (4 pts) Problems 43-46

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

What is meant by Career Planning and development ?

Answered: 1 week ago

Question

What are Fringe Benefits ? List out some.

Answered: 1 week ago