help with homework

This is a discussion on help with homework within the C Programming forums, part of the General Programming Boards category; hi I have to write a program of a vertical histogram of the letters of the alphabets.It should be like ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    6

    help with homework

    hi
    I have to write a program of a vertical histogram of the letters of the alphabets.It should be like
    * *
    * * *
    * * * *
    * * * *
    a b d f
    so far i have been able to calculate the frequency of the letters in the text but i have no idea as to how to print them vertically can anyone plz tell me how to do it
    Code:
    # include <stdio.h>
    
    main()
    {
    	int c;
    	int ar[26];
    	
    	for (i = 0; i < 26; i++)
    	ar[i] = 0;
    	while ((c = getchar()) != EOF)
    	{
    		if (c >= 'a' && c <= 'z')
    		++ar[c - 'a'];
    	}
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    When you're printing row n, how do you know whether to print a * in column m?

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You'll need to go through all the data values, and discover the minimum and the maximum values for your chart. Also, you need a tally for each letter.

    Looks like you intend to use an array[] of int's to hold the tally's, with perhaps a[0] representing A, a[1] = B, etc.

    Max - min in the data, will be the scale you need to represent with stars. You also need to get the page height and width, and the number of bars you need to represent. These last things you can "hard code" right into your program with define statements:

    Code:
    #define pagehi 20 //note no semi-colon on these lines
    #define pagewide 26
    If you have a max of say 15, and a min of 1, then your scale is 14, which will fit inside 20. If your max is 50, then we'd represent it so every third letter, earned it one more star up the chart:

    pagehi (20) = (max - min)/x where x is the number of values that will be represented per star.

    So 20x = max - min
    max - min/20 = x
    49/20 = x
    2.45 = x

    We can't print up 45% of a star, so we'd have to stick with the largest integer, 2.

    That should give you a kickstart. Remember, your program has to get the tally for each letter, and save that tally, and all the letter tally's, before it can start to compute what to use for the histogram values.

    Don't print anything, until everything has been calculated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 03:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  4. Homework
    By kermi3 in forum Windows Programming
    Replies: 5
    Last Post: 09-15-2001, 11:48 AM
  5. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21