CSE102 Homework 2 Solved

30.00 $

Category:

Description

5/5 - (1 vote)
  • Write a C code which does the following:
    • Read input.txt
    • txt will have 100 different numbers at most.
    • Count the repetitions of the integers
    • Write the repetitions to txt in ascending order. (correct ordering is 30pts )

Example

  • input.txt:

12 10 12 12              5         10 5 5 5         5

-8        5                       5              10                 4 -8 4

  • Your program counts the repetitions of integers and writes the counted values to txt
  • txt after the execution:

-8:2

4:2

10:3

12:3

5:7

Ordering

output.txt should have the numbers in ascending order( with respect to their counts). The number which repeats the least should appear first. If the counts are the same, the smallest number should appear first.

Remarks

  • You can only create arrays of size 100 or less. If you create bigger arrays you get 0. Code efficiently. You may loose points if you create unnecessary arrays.
  • Be careful with the name of the files (txt and output.txt). You won’t be given a second chance if

you make a mistake about this. Your program will fail and your grade will be 0.0.

  • Do not use any elements which is not covered in class.
  • Do not submit your code without testing it with several different scenarios.
  • Write comments in your code.
  • You can use ftell(), fseek() and other useful functions for file read/write operations.
  • Preserve the spacing in the txt. The positions of the numbers in the file should not be altered.
  • There can be negative and positive integers.
  • You can assume that the file is error-free. (i.e. there are only negative and positive integers in the file.)
  • Properly check end-of-file and succesful read/write operations.
  • Efficiency of your implementation is important. Comment about the efficiency of your code. (10 pts)

Turn in:

  • Source code of a complete C program. Name of the file should be in this format: <full_name>_<id>.c.
  • Example: c. Please do not use any Turkish special characters.
  • You don’t need to use an IDE for this assignment. Your code will be compiled and run in a command window.
  • Your code will be compiled and tested on a Linux machine(Ubuntu). GCC will be used.
  • Make sure that your program does not require specific encodings/markings/line-ending-chars. Make sure it works with a file created in a linux environment.
  • Make sure you don’t get compile errors when you issue this command : gcc <full_name>_<id>.c.
  • A script will be used in order to check the correctness of your results. So, be careful not to violate the expected output format.
  • Provide comments unless you are not interested in partial credit. (If I cannot easily understand your design, you may loose points.)
  • You may not get full credit if your implementation contradicts with the statements in this document.
  • hw2-81rpjz.zip