Puppetting on string | Let us C solution with details description and tutorials | yashwant kanetkar

 

Chapter: Puppetting on string | Let us C solution with details description and tutorials |  yashwant kanetkar

S.NChapterS.NChapter
1Decision Control Structure5Arrays
2The Loop Control Structure6Puppetting On Strings 
3The Case Control Structure7Structures
4Function and Pointer8Input/Output in C

[D] Attempt the following:

(a) Which is more appropriate for reading in a multi-word string? gets( ) printf( ) scanf( ) puts( )

Show Solutions     Hide Solutions

(b) If the string "Alice in wonder land" is fed to the following scanf( ) statement, what will be the contents of the arrays str1, str2, str3 and str4? scanf ( "%s%s%s%s%s", str1, str2, str3, str4 ) ;

Show Solutions     Hide Solutions

(c) Write a program that converts all lowercase characters in a given string to its equivalent uppercase character.

Show Solutions     Hide Solutions

(d) Write a program that extracts part of the given string from the specified position. For example, if the sting is "Working with strings is fun", then if from position 4, 4 characters are to be extracted then the program should return string as "king". Moreover, if the position from where the string is to be extracted is given and the number of characters to be extracted is 0 then the program should extract entire string from the specified position.

Show Solutions     Hide Solutions

(e) Write a program that converts a string like "124" to an integer 124.

Show Solutions     Hide Solutions

(f) Write a program that replaces two or more consecutive blanks in a string by a single blank. For example, if the input is Grim    return    to    the    planet    of     apes!! the output should be Grim return to the planet of apes!!

Show Solutions     Hide Solutions

Two-dimensional array, Array of pointers to strings
[E] Answer the following: 

E (a) How many bytes in memory would be occupied by the following array of pointers to strings? How many bytes would be required to store the same strings, if they are stored in a two-dimensional character array? char *mess[ ] = { "Hammer and tongs", "Tooth and nail", "Spit and polish", "You and C" } ;

Show Solutions     Hide Solutions

E (b) Can an array of pointers to strings be used to collect strings from the keyboard? If not, why not?

Show Solutions     Hide Solutions

[F] Attempt the following:

F (a) Write a program that uses an array of pointers to strings str[ ]. Receive two strings str1 and str2 and check if str1 is embedded in any of the strings in str[ ]. If str1 is found, then replace it with str2. char *str[ ] = { "We will teach you how to...", "Move a mountain", "Level a building", "Erase the past", "Make a million", "...all through C!" } ; For example if str1 contains "mountain" and str2 contains "car", then the second string in str should get changed to "Move a car".

Show Solutions     Hide Solutions

F (b) Write a program to sort a set of names stored in an array in alphabetical order.

Show Solutions     Hide Solutions

F (c) Write a program to reverse the strings stored in the following array of pointers to strings: char *s[ ] = { "To err is human...", "But to really mess things up...", "One needs to know C!!" } ; Hint: Write a function xstrrev ( string ) which should reverse the contents of one string. Call this function for reversing each string stored in s.

Show Solutions     Hide Solutions


F (d) Develop a program that receives the month and year from the keyboard as integers and prints the calendar in the following format. 
images 
Note that according to the Gregorian calendar 01/01/1900 was Monday. With this as the base the calendar should be generated.


Show Solutions     Hide Solutions


F (e) Modify the above program suitably so that once the calendar for a particular month and year has been displayed on the screen, then using arrow keys the user must be able to change the calendar in the following manner: Up arrow key : Next year, same month Down arrow key : Previous year, same month Right arrow key : Same year, next month Left arrow key : Same year, previous month If the escape key is hit then the procedure should stop. Hint: Use the getkey( ) function discussed in Chapter 8, problem number [L](c).

Show Solutions     Hide Solutions

F (f) A factory has 3 division and stocks 4 categories of products. An inventory table is updated for each division and for each product as they are received. There are three independent suppliers of products to the factory: (a) Design a data format to represent each transaction. (b) Write a program to take a transaction and update the inventory. (c) If the cost per item is also given write a program to calculate the total inventory values.

Show Solutions     Hide Solutions

F (g) A dequeue is an ordered set of elements in which elements may be inserted or retrieved from either end. Using an array simulate a dequeue of characters and the operations retrieve left, retrieve right, insert left, insert right. Exceptional conditions such as dequeue full or empty should be indicated. Two pointers (namely, left and right) are needed in this simulation.

Show Solutions     Hide Solutions

F (h) Write a program to delete all vowels from a sentence. Assume that the sentence is not more than 80 characters long.

Show Solutions     Hide Solutions

F (i) Write a program that will read a line and delete from it all occurrences of the word ‘the’.

Show Solutions     Hide Solutions

F (j) Write a program that takes a set of names of individuals and abbreviates the first, middle and other names except the last name by their first letter.

Show Solutions     Hide Solutions

F (k) Write a program to count the number of occurrences of any two vowels in succession in a line of text. For example, in the sentence “Pleases read this application and give me gratuity” such occurrences are ea, ea, ui.

Show Solutions     Hide Solutions

Comments

Popular posts from this blog

Array | Let us C solution with details description and tutorials | yashwant kanetkar