Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

C programming session 07


Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

C programming session 07

  1. 1. <ul><li>In this session, you will do the practice questions of Chapter 4 and Chapter 5. </li></ul>Objectives
  2. 2. <ul><li>Modify the program that determines the length of a string so that it allows input of the string from the user and displays its length. (Maximum size of the input string is 80). </li></ul><ul><li>Modify the string comparison program so that it allows input of strings and reports on whether they are the same or not. </li></ul>Chapter 4
  3. 3. <ul><li>3. A program can be easily understood if it is indented properly. This has one drawback, in terms of the size of the program on the disk. One simple way of cutting down the size significantly is described here. Assume the following piece of code: 123456789012345678901234567890 (indicates column) printf(&quot;This is the last straw&quot;); The 15 blanks at the start of the line can be replaced by the number 15 so that the line of code is now: 123456789012345678901234567890 (indicates column) 15printf(&quot;This is the last straw&quot;); Note that a saving of 13 bytes (15 - 2) has been accomplished at one shot. </li></ul>Chapter 4 (Contd.)
  4. 4. <ul><li>Write a program, which takes in a line of code from the user (maximum length of 80 characters) and prints out the condensed string (with the number of spaces occupying the first two characters in the condensed string). </li></ul>Chapter 4 (Contd.)
  5. 5. <ul><li>1. Alcatel Automatics is a company known for its marketing success. This success has been largely due to its superb data analysis programs. </li></ul><ul><li>The product manager wants some modifications to the existing programs. When running the program, he should be able to specify any of the following with the run command itself: </li></ul><ul><ul><li>%s: for displaying the product sales by each salesman as a percentage of the total salesman sales. </li></ul></ul><ul><ul><li>%p: for displaying the product sales by each salesman as a percentage of the total product sales. </li></ul></ul><ul><ul><li>%i: for displaying the product sales as an index of total sales of all products </li></ul></ul>Chapter 5
  6. 6. <ul><li>He should also be shown some help message to assist him in case he forgets what to specify with the command and should then be able to give the command again. </li></ul><ul><li>Since the calculations will be coded in separate functions, which are stored together in one file called func.c , separate from the main() function. The function available in this file are: </li></ul><ul><ul><li>intdat() : Displays the data as an index of total sales. </li></ul></ul><ul><ul><li>proddata() : Displays the data as a percentage of total product sales. </li></ul></ul><ul><ul><li>calcprodtot() : Calculates the salesman-wise totals. </li></ul></ul>Chapter 5 (Contd.)
  7. 7. <ul><li>The contents of func.c are as follows: </li></ul>Chapter 5 (Contd.)