lab 2: sizes of many gridsEN47/COMP9, Fall 2009 the problemIn this lab, you will write a program to calculate the sizes of a series of rectangular grids, as well the average grid size. To accomplish your goal, you will need to use a loop, integer and float variables, and if/else statements. The user interaction with your program should look something like below. Note: The underlined text is entered by the user; you have no control over the formatting of user input.
How many grids? 3
How many lines in grid 1? 10
How many collumns? 3
The grid size is 30 cells.
How many lines in grid 2? 5
How many columns? 3
The grid size is 15 cells.
The average grid size so far is 22.5 cells.
How many lines in grid 3? 9
How many columns? 7
The grid size is 63 cells.
The average grid size so far is 36 cells.
The sizes of 3 grids were computed.
If no area is calculated, the output should look like:
How many grids? 0
No grid size was computed.
the algorithmHere is one possible approach to this problem. You are welcome to use this algorithm as a guide in developing your solution.
the programAfter reading the problem description and sample algorithm, work out your
program on paper. You can write out the plan in C++ code or in
pseudocode, the informal description style we have seen in lecture
which follows the structure of a program but may omit detailed syntax. You may
like to refer to your
Once you have what seems to be a working program on paper, it's time to type it in and try it out. creating a skeleton programCreate a new directory called emacs grids_avg.cpp & Now type in a skeleton program for
// File: grids_avg.cpp
// Name: [put your name here]
// Date: [put the date here]
// Lab 2: Calculate the sizes and average size of n grids
#include <iostream>
#include <string>
using namespace std;
int main() {
return 0;
}
compiling the programSave your code, then bring the Terminal window to the foreground and use
g++ grids_avg.cpp If all goes well, you will see nothing, and the shell will give you another
Linux prompt. The compiler translated your C++ program into machine
language, and put the result in an executable file called Now let's try something a little different. g++ -o grids_avg grids_avg.cpp With the extra information in the command above (the " ./grids_avg coding and debuggingNow, fill in the details of your program following your plan on paper. Save your file, and compile your program. Test the performance of your program carefully, using a few normal and extreme cases. (e.g. Try one run with no grids, and another with one of the grids being of size 0.) When you are satisfied and confident that your program works as you expect,
submit the code using provide comp9 lab2 grids_avg.cpp extra creditModify your program so that the user does not have to enter the number of grids. Instead, ask the user if he or she has another grid to enter before collecting the numbers of lines and columns. For example:
Is there another grid? (y/n) y
How many lines? 10
How many columns? 3
The grid size is 30 cells.
Is there another grid? (y/n) y
How many lines? 5
How many columns? 3
The grid size is 15 cells.
The average grid size so far is 22.5 cells.
Is there another grid? (y/n) n
The sizes of 2 grids were computed.
Do not
modify your cp grids_avg.cpp grids_avg_extra.cpp When you are satisfied and confident that your extra credit program works correctly, submit it using this command: provide comp9 lab2ec grids_avg_extra.cpp |