You are on page 1of 8

CS315 Lab 013 Name: Lauren Buss 2011 Due: Friday, 10/28

Date uploaded: October 25,

1. Write a program that will count the number of vowels, consonants, punctuation marks, and whitespaces in its input. The input will be English text. As given below:

One of the most important functions of a programming language is to provide facilities for managing memory and the objects that are stored in memory. C provides three distinct ways to allocate memory for objects:

Static memory allocation: space for the object is provided in the binary at compile-time; these objects have an extent (or lifetime) as long as the binary which contains them is loaded into memory. Automatic memory allocation: temporary objects can be stored on the stack, and this space is automatically freed and reusable after the block in which they are declared is exited Dynamic memory allocation: blocks of memory of arbitrary size can be requested at runtime using library functions such as malloc from a region of memory called the heap; these blocks persist until subsequently freed for reuse by calling the library function realloc or free

For this program, the space, tab, and newline will be considered the whitespace characters. The punctuation marks consist of a period, a semicolon, a comma, a question mark, and an explamation point. Vowels are a, e, I, o, and u. The rest of the alphabetic characters in each category. Use the switch statement appropriately in your program. Test it thoroughly. Post your program code here:
/* CS315 Lab13_1.c Name: Lauren Buss Date: October 25,2011 Prorgram: 1. Write a program that will count the number of vowels, consonants, punctuation marks, and whitespaces in its input. The input will be English text. Can't get it to count the bullets. */ #include<stdio.h> #include<stdlib.h> #include<ctype.h> int main(void) { int vowels = 0;

int consonants = 0; int punctuation = 0; int whitespaces = 0; int i = 0; char c; char sent[10000]; printf("Enter the line of txt: "); fgets(sent, 10000, stdin); while(sent[i]) { c = sent[i]; putchar (tolower(c)); switch(c) { case 'a': vowels++; break; case 'e': vowels++; break; case 'i': vowels++; break; case 'o': vowels++; break; case 'u': vowels++; break; case '.': punctuation++; break; case ';': punctuation++; break; case ',': punctuation++; break; case '?': punctuation++; break; case '(':punctuation++; break; case ')':punctuation++; break; case '!': punctuation++; break; case ' ': whitespaces++; break; case '\t': whitespaces++; break; case '\n': whitespaces++; break; default: consonants ++; } i++; } printf("\nThe printf("\nThe printf("\nThe printf("\nThe return 0; } number number number number of of of of vowels: consonants: punctuation: whitespaces: %d", vowels); %d", consonants); %d", punctuation); %d\n", whitespaces);

Post your running result here:


/* CS315 Lab13_1.c Name: Lauren Buss Date: October 25,2011 Prorgram: 1. Write a program that will count the number of vowels, consonants, punctuation marks, and whitespaces in its input. The input will be English text. Can't get it to count the bullets. */ #include<stdio.h> #include<stdlib.h> #include<ctype.h> int main(void) { int vowels = 0; int consonants = 0; int punctuation = 0; int whitespaces = 0; int i = 0; char c; char sent[10000]; printf("Enter the line of txt: "); fgets(sent, 10000, stdin); while(sent[i]) { c = sent[i]; putchar (tolower(c)); switch(c) { case 'a': vowels++; break; case 'e': vowels++; break; case 'i': vowels++; break; case 'o': vowels++; break; case 'u': vowels++; break; case '.': punctuation++; break; case ';': punctuation++; break; case ',': punctuation++; break; case '?': punctuation++; break; case '(':punctuation++; break; case ')':punctuation++; break; case '!': punctuation++; break; case ' ': whitespaces++; break; case '\t': whitespaces++; break; case '\n': whitespaces++; break; default: consonants ++; }

i++; } printf("\nThe printf("\nThe printf("\nThe printf("\nThe return 0; } lauren@cslinux2:~/week08/Lab13/Lab13_1$ ./Lab13_1 Enter the line of txt: One of the most important functions of a programming language is to provide facilities for managing memory and the objects that are stored in memory. C provides three distinct ways to allocate memory for objects: Static memory allocation: space for the object is provided in the binary at compile-time; these objects have an extent (or lifetime) as long as the binary which contains them is loaded into memory. Automatic memory allocation: temporary objects can be stored on the stack, and this space is automatically freed and reusable after the block in which they are declared is exited. Dynamic memory allocation: blocks of memory of arbitrary size can be requested at run-time using library functions such as malloc from a region of memory called the heap; these blocks persist until subsequently freed for reuse by calling the library function realloc or free. one of the most important functions of a programming language is to provide facilities for managing memory and the objects that are stored in memory. c provides three distinct ways to allocate memory for objects: static memory allocation: space for the object is provided in the binary at compile-time; these objects have an extent (or lifetime) as long as the binary which contains them is loaded into memory. automatic memory allocation: temporary objects can be stored on the stack, and this space is automatically freed and reusable after the block in which they are declared is exited. dynamic memory allocation: blocks of memory of arbitrary size can be requested at runtime using library functions such as malloc from a region of memory called the heap; these blocks persist until subsequently freed for reuse by calling the library function realloc or free. The The The The number number number number of of of of vowels: consonants: punctuation: whitespaces: 268 449 9 143 number number number number of of of of vowels: consonants: punctuation: whitespaces: %d", vowels); %d", consonants); %d", punctuation); %d\n", whitespaces);

2. Write a program that writes a check. The user should enter the date, the check number,

the payee, the amount and a memo. For example, consider the following run of the program (user input is in red boldface):

Check Writing Program ______________

Date: 10/20/2011 Check Number: 351 Payee: Adam Acre Amount: 999.99 Memo: Payment on Account 345-67-8888 Check 351 Date: 10/20/2011 Pay to the Order of Adam Acres $ 999.99

Nine Hundred Ninety Nine Dollars and Ninety Nine cents

Memo: Payment on Account 345-67-8888_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Assume that the largest check that can be written is for $9999.99. Your program should output values like 300.00, 50.14, 0.12 properly both in numbers and in words.

Post your program code and its running results here:

/* CS 315 Lab13_2.c Name: Lauren Buss Date: October 27, 2011 Program: The program takes user information and then creates a check. */ #include<stdlib.h> #include<stdio.h> #include<ctype.h> #include<math.h> void pw(double n,char[]); char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"}; char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety"};

int main(void) { char date[10]; char checknum[4]; char payee_nam[25]; double amount; char memo[100]; printf("Check Writing Program\n"); printf("------------------------\n"); printf("Date: "); scanf("%s", &date); printf("\nCheck Number: "); scanf("%s", &checknum); printf("\nPayee: "); scanf("%s", &payee_nam); printf("\nAmount"); scanf("%f", &amount); if(amount >= 10000) { printf("\nAmount is too large! Please re-enter\n"); scanf("%f", &amount); } printf("\nMemo: "); scanf("%s", &memo); printf("\n"); if(amount<=0.0) printf("Enter numbers greater than 0"); printf(" Check %s\n", checknum);

printf(" Date %s\n", date); printf("Pay to the\n"); printf("Order of %s %7.2f\n", payee_name, amount); else { pw((amount/1000000),"cents"); pw(((fmod(amount/100000), 100)),"lakh"); pw(((fmod(amount/1000), 100)),"thousand"); pw(((fmod(amount/100), 10)),"hundred"); pw(((fmod(amount, 100))," "); } printf("\n\nMemo: %s return 0; } void pw(double n,char ch[10]) { (n>19)?printf("%s %s ",ten[(int)(n/10)],one[((int)fmod(n,10))]):printf("%s ",one[(int)n]); if(n)printf("%s ",ch); } Check Writing Program _ _ _ _ _ _ _ _ _ _ _ _ _ _ Date: 10/20/2011 Check Number: 351 Payee: Adam Acre Amount: 999.99 Memo: Payment on Account 345-67-8888 Check 351 Date: 10/20/2011 Pay to the Order of Adam Acres $ 999.99 Nine Hundred Ninety Nine Dollars and Ninety Nine cents Memo: Payment on Account 345-67-8888 Check Writing Program _ _ _ _ _ _ _ _ _ _ _ _ _ _ Date: 11/18/2011 Check Number: 451 Payee: Lauren Buss Amount: 9999.99 Memo: Payment on Account 345-67-8888 Check 451 Date: 11/18/2011 Pay to the Order of Lauren Buss $ 9999.99 Nine Thousand Nine Hundred Ninety Nine Dollars and Ninety Nine cents Memo: Payment on Account 345-67-8888 ", memo);

You might also like