Description
PART A (25 points)
Objectives
- To give students practice at typing in, compiling and running simple programs.
- To learn how to read in input from the user.
- To learn how to use assignment statements and arithmetic expressions to make calculations
Introduction: Programmers for a Better Tomorrow
Programmers for a Better Tomorrow is an organization dedicated to helping charities, medical societies, and scholarship organizations manage various tasks so that they can focus on making the world a better place! They have asked you and your classmates to help them develop some new programs to benefit their organizations.
Problem: Knitting for Fun and Non-Profit (knit.c)
One of the programs that Programmers for a Better Tomorrow supports knits hats, sweaters, and blankets for people who may not have enough to keep them warm. These may be sent to other places in the country or overseas.
In this program, you will ask the user how many balls of yarn they have on hand and how many yards of yarn each ball contains. Then, based on the total number of yards the user has, your program can determine how many hats OR blankets can be made.
It takes 220 yards to make a hat and 460 yards to make a sweater. If the user has 500 total yards, they would be able to make two hats or one sweater. Your program should print this information for the user.
Input Specification
- The number of balls of yarn the user has, n, where n is an integer greater than zero.
- The number of yards in each ball, y, where y is an integer greater than zero.
Output Specification
Output the result using the format below:
You can make X hats or Y sweaters.
Output Sample
Below are some sample outputs of running the program. Note that these samples are NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above.
In the sample run below, for clarity and ease of reading, the user input is given in italics while the program output is in bold. (Note: When you actually run your program no bold or italics should appear at all. These are simply used in this description for clarity’s sake.)
Sample Run #1
How many balls of yarn do you have?
6
How many yards are in each ball of yarn?
100
You can make 2 hats or 1 sweaters.
Sample Run #2
How many balls of yarn do you have?
5
How many yards are in each ball of yarn?
50
You can make 1 hats or 0 sweaters.
Sample Run #3
How many balls of yarn do you have?
3
How many yards are in each ball of yarn?
425
You can make 5 hats or 2 sweaters.
Deliverables
One source files – knit.c – is to be submitted over WebCourses.
Restrictions
Although you may use other compilers, your program must compile and run using DevCpp. So,
Remember to add the stdlib and pause lines. 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:
1) Your correctness
2) 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 5% deducted from your grade.
3) 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.
COP 3223 Assignment 1 (Parts A, B, and C)
PART B (35 points)
Objectives
- To give students practice at typing in, compiling and running simple programs.
- To read in input from the user, use assignment statements and arithmetic expressions to make calculations, and
- To learn how to use an if-statement.
Introduction: Programmers for a Better Tomorrow
Programmers for a Better Tomorrow is an organization dedicated to helping charities, medical societies, and scholarship organizations manage various tasks so that they can focus on making the world a better place! They have asked you and your classmates to help them develop some new programs to benefit their organizations.
Problem: Knitting for Fun and Non-Profit –TWO (knittwo.c)
The left over pieces from each batch needs to be minimized. So, when a batch of yarn is sent over, it is important to calculate the left-over portion for the hats and the left-over portion for the sweaters. On comparing the two left-over portions, if they are equal, a message should be printed to this effect, otherwise print out the item that will leave the smaller left-over portion.
Input Specification
- The number of balls of yarn the user has, n, where n is an integer greater than zero.
- The number of yards in each ball, y, where y is an integer greater than zero.
Output Specification
Depending on the left-over quantity, the program should say one of the following statements:
You can make X hats with zz yards left-over.
Or
You can make Y sweaters with zz yards left-over.
Or
You can make X hats or Y sweaters. In both cases, the same amount of zz yards is left-over.
Output Sample
Below are some sample outputs of running the program. Note that these samples are NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above.
In the sample run below, for clarity and ease of reading, the user input is given in italics while the program output is in bold. (Note: When you actually run your program no bold or italics should appear at all. These are simply used in this description for clarity’s sake.)
Sample Run #1
How many balls of yarn do you have?
6
How many yards are in each ball of yarn?
100
You can make 1 sweaters with 140 yards left-over.
Sample Run #2
How many balls of yarn do you have?
3
How many yards are in each ball of yarn?
425
You can make 5 hats with 175 yards left-over.
Sample Run #3
How many balls of yarn do you have?
51
How many yards are in each ball of yarn?
100
You can make 23 hats or 11 sweaters. In both cases, the same amount of 40 yards is left-over.
Deliverables
One source files – knittwo.c – is to be submitted over WebCourses.
Restrictions
Although you may use other compilers, your program must compile and run using DevCpp. 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:
1) Your correctness
2) 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 5% deducted from your grade.
3) 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.
COP 3223 Assignment 1 (Parts A, B, and C)
PART C (40 points): Repeating the Program in part B several times
Objectives
- To give students practice at typing in, compiling and running simple programs.
- To read in input from the user, use assignment statements and arithmetic expressions to make calculations, to learn how to use an if-statement, and
- To learn how to use a simple for-loop.
In this part, you must embed all of Part B in a FOR-Loop that runs N times.
At the start of Part C, prompt for an integer value of N, read it in and run the loop. So, if N is typed in at the prompt as 2, your solution to Part B will first run once, prompting for
Numballs and Numyards, and will give its result; then, it will prompt a second time
and read in a set of two values (Numballs and Numyards) and give a (second) result.
To limit the difficulties with the number of asterisks printed, you should assume that the user will type in a single digit for N.
Sample Run #1
Homany times do you wish to run the program?
2
This is Run 1
*************
How many balls of yarn do you have?
6
How many yards are in each ball of yarn?
100
You can make 1 sweaters with 140 yards left-over.
This is Run 2
*************
How many balls of yarn do you have?
3
How many yards are in each ball of yarn?
425
You can make 5 hats with 175 yards left-over.
Deliverables
Submit your program called loopknit.c, submit it over WebCourses.
Note: do NOT submit .exe files; and do NOT submit .cpp files; ONLY submit .c files.
Restrictions and Grading Details:
Same as for Parts A and B.
COP 3223 Assignment 1 (Parts A, B, and C)