Question

C ++ program that will read in prices and store them into a two-dimensional array //...

C ++ program that will read in prices and store them into a two-dimensional array

// It will print those prices in a table form and the lowest price.

// EXAMPLE

// Input:

// Please input the number of rows from 1 to 10

// 2

// Please input the number of columns from 1 to 10

// 3

//

// Input price of item (0,0): 2

// Input price of item (0,1): 4

// Input price of item (0,2): 6

// Input price of item (1,0): 1

// Input price of item (1,1): 3

// Input price of item (1,2): 5

//

//Output:

//                     2.00 4.00 6.00

//                     1.00 3.00 5.00

//                     Lowest price: 1.00

// PLACE YOUR NAME HERE

#include <iostream>

#include <iomanip>

using namespace std;

const int MAXROWS = 10;

const int MAXCOLS = 10;

int main()

{

        int numOfRows;                               // holds the number of rows used

    int numOfCols;                               // holds the number of columns used

        float priceTable[MAXROWS][MAXCOLS];         // a 2D array holding the prices

       

        cout << "Please input the number of rows from 1 to "<< MAXROWS << endl;

        cin >> numOfRows;

        cout << "Please input the number of columns from 1 to "<< MAXCOLS << endl;

        cin >> numOfCols;

       

        // Read prices into the table

        for(int row = 0; row < ___________; row++)

    {

               for(int col = 0; col < __________; col++)

               {

                       cout << "Input price of item (" << row << "," << col << "): ";

                       // Fill in the code to store the value into the table

                       cin >> ______________;

               }

        }

        // Display table with prices

        cout << fixed << showpoint << setprecision(2);

        cout << endl;

        for(int row = 0; row < ___________; row++)

        {

               for(int col = 0; col < __________; col++)

               {

                       // Fill in the code to print each element in the table

                       cout << _____________________;

                       cout << " ";         

               }

               cout << endl;

        }

       

        // Find lowest price

        float lowestPrice;

        lowestPrice = priceTable[0][0];               // make first element the lowest price

        for(int row = 0; row < ____________; row++)

               for(int col = 0; col < ___________; col++)

                       if (lowestPrice > priceTable[row][col])

                               lowestPrice = priceTable[row][col];

       

        // Fill code to display lowest price

        __________________________________________

       

        return 0;

}

Homework Answers

Answer #1
// It will print those prices in a table form and the lowest price.
// EXAMPLE
// Input:
// Please input the number of rows from 1 to 10
// 2
// Please input the number of columns from 1 to 10
// 3
//
// Input price of item (0,0): 2
// Input price of item (0,1): 4
// Input price of item (0,2): 6
// Input price of item (1,0): 1
// Input price of item (1,1): 3
// Input price of item (1,2): 5
//
//Output:
//                     2.00 4.00 6.00
//                     1.00 3.00 5.00
//                     Lowest price: 1.00
// PLACE YOUR NAME HERE
#include <iostream>
#include <iomanip>
using namespace std;
const int MAXROWS = 10;
const int MAXCOLS = 10;

int main()
{
    int numOfRows;                               // holds the number of rows used
    int numOfCols;                               // holds the number of columns used
    float priceTable[MAXROWS][MAXCOLS];         // a 2D array holding the prices

        cout << "Please input the number of rows from 1 to "<< MAXROWS << endl;
        cin >> numOfRows;

        cout << "Please input the number of columns from 1 to "<< MAXCOLS << endl;
        cin >> numOfCols;

        // Read prices into the table
        for(int row = 0; row < numOfRows; row++)
        {
               for(int col = 0; col < numOfCols; col++)
               {
                       cout << "Input price of item (" << row << "," << col << "): ";
                       // Fill in the code to store the value into the table
                       cin >> priceTable[row][col];
               }
        }

        // Display table with prices
        cout << fixed << showpoint << setprecision(2);
        cout << endl;

        for(int row = 0; row < numOfRows; row++)
        {
               for(int col = 0; col < numOfCols; col++)
               {
                       // Fill in the code to print each element in the table
                       cout << priceTable[row][col];
                       cout << " ";
               }
               cout << endl;
        }

        // Find lowest price
        float lowestPrice;
        lowestPrice = priceTable[0][0];               // make first element the lowest price
        for(int row = 0; row < numOfRows; row++)
               for(int col = 0; col < numOfCols; col++)
                       if (lowestPrice > priceTable[row][col])
                               lowestPrice = priceTable[row][col];

        // Fill code to display lowest price
        cout<<"Lowest price: "<<lowestPrice<<endl;
        return 0;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments ** Print Name and Assignment on screen ** Date ** Submit .cpp file. Demo // This program uses a type cast to avoid an integer division. #include <iostream> // input - output stream #include <fstream> //working file...
There are 7 syntax errors and 3 semantic errors in the following code segment. Please mark...
There are 7 syntax errors and 3 semantic errors in the following code segment. Please mark them in the code and explain the reason briefly in place. #include<iostream> using namespace std; int main() { cout<<”Please input the radius (in integer): ”>>endl; int 1var = 10, var=20; double area = 40; cin<< var; //get an input of the radius and store in var float continue; float const pi = 2.64; pi += 0.5; do { cout<<”The radius is ”<<”var”<<endl; //print the...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
Please use this template. In this exercise you are to use a vector to store integers...
Please use this template. In this exercise you are to use a vector to store integers entered by the user. Once you have filled the vector, ask the user for a value to search for. If found, remove the value from the vector, keeping all other values in the same relative order, and then display the remaining values. #include <iostream> #include <vector> #include <climits> using namespace std; //Fills vector with user input until user enters 0 (does not include 0...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT