COSC 2425- Program Set #1

profileAlpha67
2425PS1S26-1.pdf

Updated January 30, 2026 COSC 2425 S26

1

Program Set 1 Total Points: 10 One of the two problems below must be implemented for full credit. Read the 2425 Grading and Program Guide Sheets for additional grading/submission information. Partial credit will be given. (10 points) Section One- Choose one problem.

1. Write a program to convert a number to its ten’s complement equivalent. The ten's complement of a nonnegative integer n is the integer formed by subtracting each digit of n from 9 and then adding one to the result. For example, the ten's complement of 35 is 64 + 1, or 65. Also, note the ten's complement of 27 is 73 but the ten's complement of 0027 is 9973. Thus, the ten's complement of a number depends upon how many leading zeros are included in expressing it.

Input from the keyboard an integer value in the range [0,1000000]. Error check (validate) inputs. Output to the screen the resulting tens complement value in the appropriate field size. Finally, the program should ask if the user wants to run the program again (Check case). Refer to the sample output below. Sample Run:

Value: 35 Ten’s complement: 65 Run Again (Y/N): Y Value: 0083078 Ten’s complement: 9916922 Run Again (Y/N): n Name the program: TensCompXX.java or TensCompXX.cpp or TensCompXX.py, where XX are your initials.

Updated January 30, 2026 COSC 2425 S26

2

2. Write a program to convert strings to 7-bit ASCII. The ASCII alphanumeric code can be used to represent letters and numbers. Use the following conversion table:

Input from the keyboard a string up to 80 characters long with a space between each word. Assume proper input. Output to the screen the resulting value with one blank space between each value and a max of eight values per line. Finally, the program should ask if the user wants to run the program again (Check case). Refer to the sample output below. Sample Run:

Enter string: HELLO world! 1001000 1000101 1001100 1001100 1001111 0100000 1110111 1101111 1110010 1101100 1100100 0100001 Run Again (Y/N): y Enter string: This is computer organization class COSC 2425. 1010100 1101000 1101001 1110011 0100000 1101001 1110011 0100000 1100011 1101111 1101101 1110000 1110101 1110100 1100101 1110010 0100000 1101111 1110010 1100111 1100001 1101110 1101001 1111010 1100001 1110100 1101001 1101111 1101110 0100000 1100011 1101100 1100001 1110011 1110011 0100000 1000011 1001111 1010011 1000011 0100000 0110010 0110100 0110010 0110101 0101110

Updated January 30, 2026 COSC 2425 S26

3

Run Again (Y/N): N Name the program: ConvertASCIIXX.java or ConvertASCIIXX.cpp or ConvertASCIIXX.py, where XX are your initials.

Extra Credit: Implement the following problem for extra credit. Read the 2425 Grading and Program Guide Sheets for additional grading/submission information. Partial credit will be given. (10 points)

Write a program that reads in floating point numbers, rounds them, and then sums their values. Input will be from a data file. The first line will contain the number of decimal places needed in range [1,3] followed by an unknown number of values each on a separate line. Output to the screen the rounded total formatted to the appropriate number of decimal places given in the file. Let the user input the file name from the keyboard. The program will produce incorrect output if the numbers are added before being rounded. Finally, the program should ask if the user wants to run the program again (Check case). Refer to the sample output below. Sample File:

2 7.5399 17.9355 2.9999 3.1888 0.99968 0.55777 48.65984 14.55447 78.16936 14.3568

Sample Run:

Enter filename: rounding.txt

Value: 188.97

Run Again (Y/N): n

Name the program: RoundingXX.java or RoundingXX.cpp or RoundingXX.py, where XX are your initials.

Notes: • You only need to write the above program or programs in one language, not all three

for each problem. Which language you choose is up to you. • Remember the Program Guide for directions on comments and submission.

  • Program Set 1
  • Total Points: 10