Docsity

Assignment 12 for Programming using C | CGS 3460, Assignments of Computer Science

Toggle sidebar
bg1
CGS3460 Fall 2007
Assignment 12
Assigned: 11/19, Mon
Due: 11/28, Wed
1. Write a C program that takes at most 10 strings as input from the user. Removes duplicates,
and concatenates them into a single string where each constituent string is separated from other
by a single white space. The user indicates end of the string list with a -1. Save your program in a
file called p1.c
Example 1.
Enter 10 or less strings (max 50 characters each)
abc
xyz
123
abc
xyz
1234 567
-1
abc xyz 123 1234 567
Example 2:
Enter 10 or less strings (max 50 characters each)
1
2
3
4
5
6
1
2
3
4
1 2 3 4 5 6
2. Write a C program that takes at most 10 strings as input from the user and sorts the strings in
“Dictionary” order (the way words are arranged in a dictionary) and prints them. If the user enters
a multi-word phrase as one of strings, treat it as a string and sort it accordingly. The user indicates
end of the string list with a -1. Save this program in a file called p2.c.
Example 1:
Enter 10 or less strings (max 50 characters each)
abc
ac
aaaa
aaa
aa
zzz
xxxxxxxx
-1
pf3

Partial preview of the text

Download Assignment 12 for Programming using C | CGS 3460 and more Assignments Computer Science in PDF only on Docsity!

CGS3460 Fall 2007

Assignment 12

Assigned: 11/19, Mon Due: 11/28, Wed

  1. Write a C program that takes at most 10 strings as input from the user. Removes duplicates, and concatenates them into a single string where each constituent string is separated from other by a single white space. The user indicates end of the string list with a -1. Save your program in a file called p1.c

Example 1. Enter 10 or less strings (max 50 characters each) abc xyz 123 abc xyz 1234 567

abc xyz 123 1234 567

Example 2: Enter 10 or less strings (max 50 characters each) 1 2 3 4 5 6 1 2 3 4

  1. Write a C program that takes at most 10 strings as input from the user and sorts the strings in “Dictionary” order (the way words are arranged in a dictionary) and prints them. If the user enters a multi-word phrase as one of strings, treat it as a string and sort it accordingly. The user indicates end of the string list with a -1. Save this program in a file called p2.c.

Example 1: Enter 10 or less strings (max 50 characters each) abc ac aaaa aaa aa zzz xxxxxxxx

Strings in "Dictionary" sorted order aa aaa aaaa abc ac xxxxxxxx zzz

Example 2: Enter 10 or less strings (max 50 characters each) this is a test case

Strings in "Dictionary" sorted order a case test this is

Note that string aa comes before aaa.

  1. Write a C program that obtains a (possibly multi-line) string from the user and reports back the number of characters, words and lines in it. The user indicates the end of input by EOF character. EOF is not a part of the string. Newline is not to be counted as a characters or a word. Spaces and tabs are counted as characters. User is expected to enter EOF on a new line. You can assume that no blank line is present in the input. Save this program in a file called p3.c. [Extra credit problem: If you do this correctly, you can score 30% more points on this whole assignment]

Example 1: Enter a string (max 100 characters): this is a test This string has 14 character(s), 4 word(s) and 1 line(s)

Example 2: Enter a string (max 100 characters): this is a test This string has 12 character(s), 4 word(s) and 3 line(s)

Example 3: Enter a string (max 100 characters): this is a test This string has 13 character(s), 4 word(s) and 2 line(s)

The large blank space on line 1 is a tab.

Example 4: Enter a string (max 100 characters): 1 2