Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

some C programming problems...

1.)Dates are commonly printed in several different formats in business correspondence.  Two of the more common formats are:
     07/21/97 and July 21, 1997
Write a program that reads a date in the first format and prints the date in the second format.


2.)Write a program that reads a line of text and prints a table indicating the number of occurrences of each letter of the alphabet in the text.


3.)Implement a multipurpose sorting program in C using function pointers.  The following functions are expected.
a) bubble()  -> for sorting
b) swap()    -> to interchange two values in two locations
c) ascending() -> to verify the two values passed to this                   function are in ascending order
d) descending() -> to verify the two values passed to this                    function are in descending order
The bubble() function should be passed with the array of integers, the array size and the pointer to the function ascending() or descending() (depending upon
the user's choice).   Use bubble sort.
0
suelow
Asked:
suelow
1 Solution
 
ozoCommented:
If you're having problems on your final exam, we can try to help you to understand why the code you wrote is not doing what you expected,
but it would be unethical to help you cheat, or to spread Y2K bugs.
0
 
agolanCommented:
I'll second ozo.
0
 
JYoungmanCommented:
#!/bin/sh
# Answer to question 1.
# Requires GNU date(1).
date --date="$1"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
suelowAuthor Commented:
ozo, you have misunderstood my problems, it is just an assignment of mine and now I'm searching the opinions from the experts for pointing on how to solve the above problems in more efficient way. you can ommit the Y2K problem.
0
 
ozoCommented:
I'm sorry if I misunderstood.  Many of us would be happy to help you find ways to improve the efficiency of your programs,
as long as it wasn't being unfair to other students, and didn't interfere with your own efforts to learn programming.
But it hard to know where your program is being inefficient unless we can see your program first.
About the only thing appatent so far is that you might want to use a more efficient sort than bubble sort.
Perhaps a partition exchange sort or a radix sort, depending on what kind of data you're expecting.
Or just use the standard qsort function.
0
 
RONSLOWCommented:
Please don't put an assignment question here and expert an expert to answer it .. we won't.

If you had asked a particular question about your assignment, then we could/can help you (eg. "I am having trouble with the bubble sort .. it seems to hang .. here is my code, can you help me find the problem?")

However, simply putting your assugnment question up verbatim as a question, with no other comments or indication of what problems you are having, just won't get a response (well, not the sort of response you want).

Try doing the assignment yourself, then come back to us with whatever problems you have with the program and/or concepts

0
 
suelowAuthor Commented:
Here are the solutions for Q1, Q2 and Q3...

Q1)
#include <stdio.h>

void main()
{
      int d, m , y;

      char *month[13] = {"Zero", "January", "February",      
                           "March", "April","May", "June",      
                           "July", "August", "September"
                     "October", "November", "December"};

      char slash;

      printf("Enter date (mm/dd/yy) >");
      scanf("%d%c%d%c%d", &m, &slash, &d, &slash, &y);

      printf("\n%s %d, 19%d", month[m], d, y);
}


Q2)
#include <stdio.h>
#include <ctype.h>

void main()
{
      char text[80];
      int alpha[26];
      int count[26];
      int i, n;

      gets(text);

      for(i = 0;i < 26;i++)
      {
            count[i] = 0;
            alpha[i] = 97 + i;
      }

      i = 0;
      while(text[i] != '\0')
      {
            n = tolower(text[i]) - 97;
            count[n] = count[n] + 1;
            i++;
      }

      for(i = 0;i < 26;i++)
      {
            if(count[i] != 0)
                  printf("The character %c occurs %d times.
                                \n", alpha[i], count[i]);
      }
}


Q3)
#include <stdio.h>
#include <conio.h>

#define MAX 50

void swap(int *, int *);

void main()

{
      void bubble(void (*)(int [], int), int[], int);
      void (*order[2])(int [], int);
      void ascending(int[], int);
      void descending(int [], int);


      int a[MAX];
      int i, n, choice;

      clrscr();
      for(i = 0;i < 50;i++)
            a[i] = 0;

      printf("Enter number of elements >");
      scanf("%d", &n);

      printf("\nEnter %d elements separate by space >", n);

      for(i = 0;i < n;i++)
            scanf("%d", &a[i]);

      order[0] = descending;
      order[1] = ascending;

      printf("\n\tMenu");
      printf("\n0.\tDescending Order.");
      printf("\n1.\tAscending Order.");
      printf("\nYour choice >");
      scanf("%d", &choice);

      bubble(order[choice], a, n);

      for(i = 0;i < n;i++)
            printf("%d ", a[i]);
}



void bubble(void (*x)(int y[], int n), int y[], int n)
{
      (*x)(y, n);
}

void ascending(int y[], int n)
{
      int i, j;

      for(i = 0;i < n - 1;i++)
            for(j = 0;j <= n - 2;j++)
            {
                  if(y[j] > y[j + 1])
                        swap(&y[j], &y[j + 1]);
            }
}

void descending(int y[], int n)
{
      int i, j;

      for(i = 0;i < n - 1;i++)
            for(j = 0;j <= n - 2;j++)
            {
                  if(y[j] < y[j + 1])
                        swap(&y[j], &y[j + 1]);
            }
}

void swap(int *a, int *b)
{
      int temp;
      temp = *a;
      *a = *b;
      *b = temp;
}


0
 
suelowAuthor Commented:
ozo,
Is that the best way to solve these kind of problems ?
0
 
ozoCommented:
Depending on your compiler, your Q2) program may do interesting things with
{|}~{|}~abcdefg
or
0123456789abcdefghijklmnopqrstuvwxyz
or
[\]_`[\]_`abcdefghijklmnopqrstuvwxyz
0
 
suelowAuthor Commented:
ozo,
I'm using Turbo C while compiling the source code. The output I got for Q2 is what I expected.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now