Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a c++ Project I need help with, please note that we have not gone into arrays or the advanced stuff. Here are the

I have a c++ Project I need help with, please note that we have not gone into arrays or the advanced stuff.

Here are the instructions:

This project uses nested loops. - the outer loop processes vegetable categories - the inner loop processes seasons within a vegetable category. There are the same number of seasons for each vegetable category.

Your program will use nested loops, as seen in the sample run given below.

For a particular vegetable category in the outer loop, the inner loop will process all seasons, one by one. - Input the number of seeds, the number of plants and the unit price of a plant. - Keep a running total of: - the growing ratio of plants to seeds - the total selling price of all plants At the end of the inner loop report the growing ratio and total selling price for that category

After all categories have been processed, report the following: - The category of the best growing group (having the highest ratio) - The category of the best selling price (having the largest sales)

Sample Run - note all user input data ( cin >> ) is shown in red

Use of the setw(... ) and the setpresion(... ) will customize the program output. Read the ioManip.cpp in the "Instructor's Sample Program" in Lesson 2.

/* Enter the number of the veg catagory : 2 Enter the number of the seasons : 2 ---------------------------------------------------------- catagory 1 : season 1 : Enter Number of Seeds : 13 Enter Number of Plants : 11 Enter UnitPrice : 1.2 season 2 : Enter Number of Seeds : 14 Enter Number of Plants : 10 Enter UnitPrice : 2.1 growing ratio for catagory 1 : 78.02% total sold price for catagory 1 : 34.20 ---------------------------------------------------------- catagory 2 : season 1 : Enter Number of Seeds : 12 Enter Number of Plants : 11 Enter UnitPrice : 1.1 season 2 : Enter Number of Seeds : 14 Enter Number of Plants : 12 Enter UnitPrice : 1.4 growing ratio for catagory 2 : 88.69% total sold price for catagory 2 : 28.90 ---------------------------------------------------------- ---------------------------------------------------------- The best growing group is Catagory 2, with the best growing ratio : 88.69% The best total selling price is Catagory 1, with the price : 34.20 Press any key to continue . . . */

Here is my sample code:

#include

#include

using namespace std;

int main()

{

int num_of_veg_categories, num_of_seasons, seeds, plants, total_seeds, total_plants;

double unit_price, ratio_perc, total_price;

double bestRatio = 0; // ***set up for Ratio comparison

double bestAmount = 0; // ***set up for total sold price comparison

total_seeds=0;

total_plants=0;

total_price=0;

cout << setprecision(2) << fixed;

cout << "Enter the number of veg category: ";

cin >> num_of_veg_categories;

cout << "Enter the number of seasons: ";

cin >> num_of_seasons;

for (int i=1; i<=num_of_veg_categories; i++) //*****Errors

{

cout << "Category" << i << ":" << endl;

for (int j=1; j<=num_of_seasons; j++)

{

cout << "Season" << j << ":" << endl;

cout << "Enter the number of seeds: ";

cin >> seeds;

cout << "Enter the number of plants: ";

cin >> plants;

cout << "Enter the unit price: ";

cin >> unit_price;

total_seeds+=seeds;

total_plants+=plants;

total_price+= plants*unit_price;

}// ***seasons

ratio_perc= ( (double) total_plants / total_seeds) / num_of_seasons*100;

if(ratio_perc > bestRatio)

{

bestRatio = ratio_perc;

......

}

if(total_price > bestAmount)

{

bestAmount = total_price;

.....

}

} //***outer loop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions