Homework Assignment 10

February 3, 2019 | Author: rockondog087_9739178 | Category: String (Computer Science), Array Data Structure, Computer Data, Software Engineering, Areas Of Computer Science
Share Embed Donate


Short Description

Homework Assignment 10...

Description

Lawrence Technological University Department of Mathematics and Computer Science MCS 1142 ntroduction to C ! "all 2##$ This homework assignment builds builds on the previous assignments. In the last assignment you called calcAndPrint () with 3 input parameters parameters 2 of which were arrays. One array contained the  format strings used in the printf() statements in calcAndPrint (). !or this assignment I want you add a new function" modifyFormats  modifyFormats()" that will be called on the array of format strings like this#

 modifyFormats(f  modifyFormats(formats[ ormats[], ], 5); where formats is the array of format strings and  is the integer number of entries in the array.  modifyFormats() from the main() function right after you copy the format $ou should call modifyFormats strings into the array but before you call calcAndPrint ().

 modifyFormats() I want you to modify the format strings ( formats%&) so that the words In modifyFormats radius" area" and circum are in capital letters. To do this use the string manipulation function strstr () to pick out the beginning of the substring in 'uestion (either radius" area" or circum). et remember you can modify individual characters in a string by using a pointer to the character like this *

*subStr = ‘!;  +lso remember you you can advance a substring pointer by simply simply incrementing it like this#

subStr""; Therefore you can combine these commands commands to replace a lower case word with with upper case. !or eample" to replace the word radius you would do the following#

*subStr *subStr *subStr *subStr *subStr *subStr

= = = = = =

##; #A#; #$#; #%#; #&#; #S#;

subStr""; subStr""; subStr""; subStr""; subStr"";

The five elements in formats  should be each of the five different format strings used in the  printf() function calls in calcAndPrint (). These strings should should be defined in in the main function like this#

'' rat t format formats[-] = .ircl formats[4] = .ircl formats[3] = .ircl formats[] = .ircl formats[7] = .ircl

strin+s /d radius0 /d circum0 /d ara0 /d circum0 /d ara0

1t1t/23f1n.; 1t1t/23f1n.; 1t1t/23f1n1n.; 1t1t6ot alculatd1n.; 1t1t6ot alculatd1n1n

Once these character strings are created and stored in formats " calcAndPrint () can be called with the three input parameters like this#

calcAndPrint(, radii, formats); Inside calcAndPrint ()" the printf() calls should now use the entries in formats for the format strings rather than string literals. ,elow is an eample of how the printf() call to print a circle radius would look#

'' alculat and print circumf and ara for t circl  printf(formats[-], loop8countr"4, radii[loop8countr]); $ou can use the input file you used for assignment -. It should have the structure below#  2 3

./ /./ -.3

The output should have the following format (0lease note the capital letters1)# ircle  +4I56# ircle  I58# ircle  +9+#

777.77 777.77 ot alculated

ircle 2 +4I56# ircle 2 I58# ircle 2 +9+#

777.77 ot alculated 777.77

ircle 3 +4I56# ircle 3 I58# ircle 3 +9+#

777.77 ot alculated ot alculated

4on:t forget the following program head for all programs submitted for grading.

// Program Author: // Student ID: // Email Address: // "ame o# Program: // Program Due Date: // '()e$ti*e: assignment // Program Des$ri,tion: // onor ode: // elses //

9n;oy1

Your name xx000012345 xxltu!edu "ame o# Program!$ %%&DD&YY +he Instru$tors des$ri,tion o# the ,rogramming +he Students des$ri,tion o# ho- the ,rogram -or.s I ha*e neither gi*en nor re$ei*ed unauthoried aid in $om,leting this -or. nor ha*e I ,resented someone -or. as m o-n

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF