# RadioCost - cin >> component_cost[0][0] >>...

This preview shows pages 1–2. Sign up to view the full content.

// Matrix multiply problem - radio example #include <iostream> #include <iomanip> #include <cassert> using namespace std; const int MAX=5; // C = A * B void matMult(int A[][MAX], double B[][MAX], double C[][MAX], int rowsA, int colsA, int rowsB, int colsB, int &rowsC, int &colsC); int main() { int i, j, num_radio_types, num_components, rowsC, colsC; int component_matrix[MAX][MAX]; double component_cost[MAX][MAX]; double radio_cost[MAX][MAX]; // Ask the user about the size of our problem cout << "Enter the number of radio types: "; cin >> num_radio_types; num_components = 3; // capacitors, resistors and transistors assert(cin); assert(0 < num_radio_types & num_radio_types // input component data cout << "For each type, enter the number of capacitors, resistors, and transistors\n"; for (i = 0; i < num_radio_types; i++) for (j = 0; j < num_components; j++) cin >> component_matrix[i][j]; cout << "Enter the cost of capacitors, resistors, and transistors: ";

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cin >> component_cost[0][0] >> component_cost[1][0] >> component_cost[2][0]; assert(cin); // call matrix multiply routine to calculate radio costs matMult( component_matrix, component_cost, radio_cost, num_radio_types, num_components, num_components, 1, rowsC, colsC); // display results cout << setiosflags(ios::showpoint | ios::fixed) << setprecision(2); for(i = 0; i < num_radio_types; i++) cout << "Radio type " << i+1 << " costs \$" << radio_cost[i][0] << endl; return 0; } // matrix multiply function void matMult(int A[MAX], double B[MAX], double C[MAX], int rowsA, int colsA, int rowsB, int colsB, int &rowsC, int &colsC) { int i, j, k; assert(colsA == rowsB); rowsC = rowsA; colsC = colsB; for(i = 0; i < rowsA; i++) for(j = 0; j < colsB; j++) { C[i][j] = 0.0; for(k=0; k < colsA; k++) C[i][j] += A[i][k] * B[k][j]; } return; }...
View Full Document

## This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

### Page1 / 2

RadioCost - cin >> component_cost[0][0] >>...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online