
Problem: Autonomous Robot Selection (marsrobots.c)
Objectives
- To reinforce the use of loops.
- To learn how to read information from files.
Introduction: Mission to Mars
Your friend has been playing a new Mars Colony simulator nonstop! They are always talking about how cool it would be if they could be a on the first real-life mission to Mars! To amuse your friend, you have decided to create a series of programs about the possible first colony on Mars.
Problem: Autonomous Robot Selection (marsrobots.c)
For our first mission to Mars, we will send only autonomous robots to set up our colony. Our robot development team has recently contacted us to say that they have numerous types of robots with different attributes to choose from. We now need to decide what we will prioritize in our robots:
- Cost – this attribute specifies how expensive each unit will be
- Efficiency – this attribute specifies how long it takes each unit to complete a task
- Battery Life – this attribute specifies how long each unit’s battery will last before recharging
In this program we want to read information from a file about the robots we could potentially send to Mars. Ask the user for the name of this file and process the file they specify.
For each robot, we will have a manufacturing number, a cost, an efficiency rating, and an expected battery life in hours. After we have read all the information, we want to print out which robot – identified by manufacturing number – will be best for each criterion.
- Cost – the lowest price will be considered the best
- Efficiency – the lowest rating will be considered the best
- Battery Life – the highest value will be considered the best
If a single robot has the best rating for 2 or more attributes, we should recommend it above all the other options.
Input Specification
1. The file name will be a string less than 50 characters in length
Input File Format
The first line of the input file will contain a single integer n (5 ≤ n ≤ 10000), denoting the number of potential robots, for which information is listed in the file. The following n lines will have all the information for all the robots with one robot's information on a single line. Each line will have the following format:
ManufacturingID Cost EfficiencyRating BatteryLife
- comment major sections of code addressing: “What does this block do?” and “Why did I implement this block in this way?”
- place comments above the line(s) to which it applies
- use inline comments (//) and leave one space between // and the comment’s first character
- All variables should be declared at the top of your functions (in this program, only main is needed) and should have meaningful names
- Be sure to declare main with: int main(void) {
- Indent the contents of main four spaces or one tab
- leave a space on both sides of any binary operators you use in your code (i.e., operators that take two operands). For example, use (a + b) - c instead of (a+b)-c.
- keywords if, while, and for should have a single space after them
- contents of if statements and loops should be indented four spaces or one tab
- conditions should not have any space immediately after each ( or immediately before each ) .
Deliverables
One source file: marsrobots.c for your solution to the given problem submitted over WebCourses.
Restrictions
Although you may use other compilers, your program must compile and run using Code::Blocks. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Also, make sure you include comments throughout your code describing the major steps in solving the problem.
Grading Details
Your programs will be graded upon the following criteria:
- Your correctness
- Your programming style and use of white space. Even if you have a plan and your program works perfectly, if your programming style is poor or your use of white space is poor, you could get 10% or 15% deducted from your grade.
- Compatibility – You must submit C source files that can be compiled and executed in a standard C Development Environment. If your program does not compile, you will get a sizable deduction from your grade.