BSIT SEMESTER #01
UROOJ ASGHAR KHAN
02-135242-006
Task 1: Inventory Tracking Module (Matrix Addition)
Suppose you are managing a warehouse where you need to track inventory levels of
different products across multiple locations. Each location has its own inventory count
for various products, and you want to consolidate this information to get an overall
view of inventory levels.
Matrix A represents the inventory levels of various products across different
locations for the current month.
Matrix B represents the inventory levels of the same products across the same
locations for the previous month.
Write a C++ program that takes input for matrices A and B, performs matrix addition,
and outputs the consolidated inventory levels for each product across different
locations.
CODE:
#include <iostream>
#include <vector>
using namespace std;
const int ROWS = 3;
const int COLS = 4;
void inputMatrix(int matrix[ROWS][COLS], const string& matrixName) {
cout << "Enter inventory levels for " << matrixName << " (Matrix " << matrixName << "):"
<< endl;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
cout << "Location " << i + 1 << ", Product " << j + 1 << ": ";
cin >> matrix[i][j];
}
}
}
,CP LAB ASSIGNMENT
BSIT SEMESTER #01
UROOJ ASGHAR KHAN
02-135242-006
void addMatrices(int matrixA[ROWS][COLS], int matrixB[ROWS][COLS], int result[ROWS]
[COLS]) {
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
result[i][j] = matrixA[i][j] + matrixB[i][j];
}
}
}
void displayMatrix(int matrix[ROWS][COLS], const string& matrixName) {
cout << "\n" << matrixName << " (Consolidated Inventory Levels):\n";
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
cout << matrix[i][j] << " ";
}
cout << endl;
}
}
int main() {
int matrixA[ROWS][COLS];
int matrixB[ROWS][COLS];
int result[ROWS][COLS];
inputMatrix(matrixA, "Current Month");
inputMatrix(matrixB, "Previous Month");
addMatrices(matrixA, matrixB, result);
displayMatrix(result, "Consolidated Inventory Levels");
return 0;
}
, CP LAB ASSIGNMENT
BSIT SEMESTER #01
UROOJ ASGHAR KHAN
02-135242-006
OUTPUT:
Task 2: Students Grades Organization (Transpose)
You have a matrix where each row represents a student and each column represents
an assignment. However, your grading system is set up in such a way that rows
represent assignments, and columns represent students. To analyze the grades more
effectively, you need to transpose the matrix so that each row represents an
assignment and each column represents a student.
Write a C++ program that takes input for the original matrix representing student
grades, calculates its transpose, and outputs the transposed matrix where rows
represent assignments and columns represent students. Additionally, provide average
grades for each assignment.
CODE:
#include <iostream>
#include <vector>
#include <iomanip>