posted by .

Write a C program to sort the bags by weight. Assume that the input is given in
a file. Each line of the input file corresponds to one polythene bag. For example
a line in the file as below
corresponds to a bag containing four 10 paisa coins and two coins of 20 and 50
paisa each.

  • programming -

    This is what I would do:

    1. Open the file for reading (use fopen()) and read in the file, one line at a time. Each line will be read into a string (or character array).
    2. The line will be read in one number at a time using sscanf, until no more number is available, or use the strtoken() to read them all into an array.
    3. The numbers will be added up, and the sum put into an array. No index array is required if the question does not require identifying the order of the bags.
    4. Sort the resulting array using a method of your choice.
    5. output the resulting sorted array.

    Feel free post your code for help in debugging or verification.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. programming

    How do I delete a file on my shared LAN network with vbs?
  2. window XP

    Which of the following is true of the Encrypting File System (EFS)?
  3. Programming and algorithms

    For each of the following problems, use the top-down modular approach and pseudocode to design a suitable program to solve it. 1. Input names of students from the user, terminated by ZZZ, and create a data file GRADES with records …
  4. Programming

    2. Then it should prompt the user for the input file name of the file containing the data to sort. 3. If the program can't open the file or if no file name is entered (^d or ^z is entered for EOF), it should print an error message …
  5. programming

    You are required to design and write an application that will analyze an input file (InputFile.txt); the file contains a date on each line. Your algorithm should output all the missing dates, excluding Saturdays and Sundays. You should …
  6. programming logic raptor

    1. a.input names of students from the user, terminated by "zzz", 0,0,0, and create a data file grades with records of the following form: student (string), test1 (integer), test2(integer), test3 (integer) b. display the contents of …
  7. morrisville

    Problem 3: Baggage Name your source code file You will write a program that simulates the actions of luggage handling for a large aircraft. As bags arrive they are loaded into containers. Each bag has a different weight and …
  8. programming

    b. Write a well-commented C++ program that reads data from the input file employee.txt. Each input line consists of last name, first name, base salary, total sales, and number of years of service. Store the output in the file employees_payCheck.txt. …
  9. c programming

    Write a program to read from a file called "input.txt" information about 5 workers. Each line would contain two values respectively, an employee ID and the employee's monthly salary. Assume that the data from the input file is stored …
  10. Programming

    I am having a problem with something. i nead to assing values to parameters from input.dat file without using fscanf. i need to use the terminal like a.out<input.dat>output.out i have a file like this GEN 0.0 2.1351 0.00001 500 …

More Similar Questions