Docsity

Computer Science I: Practice Programs - Alphabet & Length Comparison, Structs & Array Ops, Assignments of Computer Science

Toggle sidebar
bg1
Practice Programs For Computer Science I
1) Write a program that prompts the user to enter 5 strings and outputs the string that
comes first in alphabetical order.
2) Edit program #1 so that it prints out the string that comes last in alphabetical order.
3) Edit program #1 so that it prints out the shortest string of those entered. If there are
two strings that are the shortest, print out the one that comes first alphabetically.
4) Edit program #1 so that it prints out the longest string of those entered. If there are two
strings that are the longest, print out the one that comes last alphabetically.
5) Create a struct that stores a string of up to 9 characters and an integer.
6) Use the struct created in #5 to write a program where you read in 5 pairs of strings and
integers. Use this information to create and fill an array of 5 structs. Then print out all of
the information entered.
7) Edit your program from #6 to read in the information from a file. You can choose the
file format.
8) Edit your program from #7 so that it only prints out information about the structs
which store the number 10.
9) Edit your program from #8 so that it sorts the structs by order of number (increasing).
If there are ties, the ties are broken by the strings.

Partial preview of the text

Download Computer Science I: Practice Programs - Alphabet & Length Comparison, Structs & Array Ops and more Assignments Computer Science in PDF only on Docsity!

Practice Programs For Computer Science I

  1. Write a program that prompts the user to enter 5 strings and outputs the string that comes first in alphabetical order.
  2. Edit program #1 so that it prints out the string that comes last in alphabetical order.
  3. Edit program #1 so that it prints out the shortest string of those entered. If there are two strings that are the shortest, print out the one that comes first alphabetically.
  4. Edit program #1 so that it prints out the longest string of those entered. If there are two strings that are the longest, print out the one that comes last alphabetically.
  5. Create a struct that stores a string of up to 9 characters and an integer.
  6. Use the struct created in #5 to write a program where you read in 5 pairs of strings and integers. Use this information to create and fill an array of 5 structs. Then print out all of the information entered.
  7. Edit your program from #6 to read in the information from a file. You can choose the file format.
  8. Edit your program from #7 so that it only prints out information about the structs which store the number 10.
  9. Edit your program from #8 so that it sorts the structs by order of number (increasing). If there are ties, the ties are broken by the strings.