SampleProgram - Sample Problem that Utilizes Files and...

Info icon This preview shows pages 1–3. Sign up to view the full content.

Sample Problem that Utilizes Files and Strings You are given a file with first and last names of employees as well as their position in the company. In addition, all clerks are given a numerical ID. Your job is to read in a file with the names of these employees and sort them in the following order: Bosses come first, and all bosses should be listed alphabetically by last name (you are guaranteed that each boss has a different last name.) All clerks will be listed after the bosses and they will be listed in increasing numerical order by their ID. (All of these IDs will be distinct positive integers.) The input file will have one integer, n, on the first line specifying the number of employees to sort. The following n lines will contain one employee record each. Each line will have the first name followed by the last name followed by their position. If they are a clerk, then this will be followed by a positive integer that is their ID. You are guaranteed that n is less than or equal to 60, and that there will be 10 or less bosses and 50 or less clerks. Also, all first and last names will be 19 characters or less. Here is a sample file: 6 Bob Jones boss David Kern clerk 12 Carrie Wilson boss Michael Carraway clerk 7 Sarah Wilbur clerk 3 John Copley clerk 9 You must design a program to read in a file and produce an output file in the same format, but that lists the employees in the sorted order mentioned above. For the following file, the output file would be: 6 Bob Jones boss Carrie Wilson boss Sarah Wilbur clerk 3 Michael Carraway clerk 7 John Copley clerk 9 David Kern clerk 12
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

SOLUTION: // Arup Guha // 11/24/04 // Solution to practice problem from 11/23 optional session.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • Guha
  • Natural number, workers, HTTP 404, IfP, const struct employee

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern