首页 > 其他分享 >CMPSC122 Matrix类实现细节

CMPSC122 Matrix类实现细节

时间:2023-08-20 09:14:16浏览次数:35  
标签:function Matrix value should 细节 following CMPSC122 matrix


CMPSC122 Matrix
Matrix Class
A matrix is rectangular array of items laid out in rows and columns. The dimensions, or size, of a matrix can be expressed as m x n or m-by-n, where m is the number of rows in the matrix and n is the number of columns in the matrix.

The individual elements in A can be expressed as ai,j, where i (the row) is a number from 1 to m and j (the column) is a number from 1 to n. For example, the value at element a1,3 is 2.

Write a program (called matrix.cpp) that does that following:

Implement a class called Matrix that:
Contains private member fields for the number rows and columns of the matrix
Contains a public member field to contain the matrix elements
This should be a 2D array of integers that is implemented dynamically
Contains five public functions
add function, that adds two same sized matrices together and returns a new matrix with the result
subtract function, that subtracts two same sized matrices together and returns a new matrix with the result
multiply function, that performs proper matrix multiplication and returns a new matrix with the result
scalar function, that performs scalar multiplication with an integer value and a matrix, and returns a new matrix with the result
print function, that outputs the contents of the matrix in tabular form that matches the dimensions of the matrix
Contains a non-default constructor
Constructor that accepts size information, and dynamically creates the matrix
Contains a destructor
That properly handles discarding the dynamically created 2D array (using delete and setting the member field to null
Prompts the user for:

The dimensions of a first matrix
The contents of the first matrix, which is then filled into the newly created matrix object instance.
The dimensions of a second matrix
The contents of the second matrix, which is used to fill the newly created matrix instance
Sample prompts with appropriate user responses:

Number of Rows in Matrix 1: 5
Number of Columns in Matrix 1: 2
Values of Matrix 1 (expecting 10): 6 7 10 3 5 31 0 9 2
Note: You must use the above format for entering the values of the matrix.
When entering values to fill a matrix, all values should be provided on one line.

Performs the following calculations and prints each result using the print function
Each of the four matrix mathematical methods should be called, each result stored in a new object
If the dimensions of the two matrices involved do not allow for the operation to be performed, skip performing this calculation, and display a message stating that step has been skipped.
For example, if I have a 3x4 matrix and a 4x2 matrix, I cannot add or subtract these together, but I can perform multiplication
Each calculation should be printed with a full explanation
For scalar multiplication, you can either use an integer literal or generate a random integer. Just be sure to print the value of the integer value as part of the output when performing this function.
The calculation being performed should be explained; and the contents of each matrix or value involved should be printed and identified.
Matrix Class with Overloaded Operators
Using the class from the first portion of the assignment, write a program (called matrix_ops.cpp) that does the following:

Overloads the following operators using friend:
+ Replicate the functionality of the add function from matrix.cpp
- Replicate the functionality of the subtraction function from matrix.cpp
* Overload this to replicate the functionality of both the matrix multiplication and scalar multiplication functions from matrix.cpp. This operator should be overloaded a total of 3 times.
<< Replicate the functionality of the print function from matrix.cpp
Used in the following way: cout << matrix_instance1;
>> Used as the only way to fill in a matrix with values. Used in the following way: cin >> matrix_instance1;
Remove the five public functions of the Matrix class, and use only overloaded operators to perform the same functionality/output as in the matrix.cpp
Performs the following calculations and prints each result using the overloaded >> operator
Each of the four matrix mathematical methods should be called, each result stored in a new object. Be sure you invoke scalar multiplication once for each overloaded operator
int * Matrix
Matrix * int
If the dimensions of the two matrices involved do not allow for the operation to be performed, skip performing this calculation, and display a message stating that step has been skipped.
For example, if I have a 3x4 matrix and a 4x2 matrix, I cannot add or subtract these together, but I can perform multiplication
Each calculation should be printed with a full explanation
For scalar multiplication, you can either use an integer literal or generate a random integer. Just be sure to print the value of the integer value as part of the output when performing this function.
The calculation being performed should be explained; the contents of each matrix or value involved should be printed and identified.
Compiling the Program
Use the following command to compile your classes:

g++ -Wall -o <output_name> <program_name.cpp>
Example:

g++ -Wall -o matrix matrix.cpp
Remember: Your code must successfully compile without any warnings or errors, or a zero will be given for the assignment.

Submission
Electronic Submission
Your two source code files (matrix.cpp, matrix_ops.cpp)
Zip file of source code (can include optional README file to demonstrate how to run your program) submitted via CANVAS drop box by close of assignment

 

标签:function,Matrix,value,should,细节,following,CMPSC122,matrix
From: https://www.cnblogs.com/longtimeagos/p/17643569.html

相关文章

  • 采样率——选择合适的声音细节
    高采样率能展示出更高的细节但是,高品质不一定是好的当把低采样率的素材放在高采样率的轨道里面就会有提示......
  • PMP考试有哪些细节不可忽视?小白都要知道!
    PMP®考试是对整个学习备考效果的检验,直接关系到考生能否顺利拿到证书。但很多同学是第一次参加PMP®考试,对于考试中的一些细节和注意事项并不是很了解,为了帮助各位同学有更好的临场发挥,顺利拿到证书,才聚专门整理了PMP®考试中的一些重要细节和需要注意的事项,希望能对大家有所帮助......
  • Tita 升级|产品细节体验优化
    功能一:企微试用版客户,超管用户增加一个【进入企微管理应用授权】的快捷入口Tita-OKR和新绩效一体化管理平台具体规则如图所示:功能二:KR负责人修改信息指数,支持目标O负责人收到提醒KR负责人≠O负责人,通知语:XXX将目标[XXXX]中关键结果[XXXXX]的信心指数由X分更......
  • Matrix Power Series
    描述Givena n × n matrix A andapositiveinteger k,findthesum S = A + A2 + A3 +…+ Ak.题意已知矩阵A,算A^1+A^2+....+A^k,元素对m取模二分递归,如果k为偶数,,因为是等比矩阵,所以前一半和后一半就有一个比例,所以sum(1,k)=sum(1,k/2)+sum(1,k/2......
  • tzoj7929: Matrix Power Series
     题意给定一个n*n大小的矩阵A,求以A为公比的等比数列的前k项和。解题思路直接从1到k矩阵快速幂每项相加肯定是会超时的,而如果用公式计算需要求逆矩阵非常麻烦,而且有可能会溢出。因此我们使用分治求解。当n为奇数时, 当n为偶数时, 分治求解即可。#include<bits/stdc+......
  • 操作系统之间的设计理念和细节--待补充
    操作系统要考虑硬件的变化-硬件迭代变化非常快芯片架构--x86、ARM、申威、龙芯、RISC-V五种架构computerarchitecturekernelmodeusernode专业和降低门槛使用间隔重复应用程序(如Anki)来记忆常用的命令WindowsandAppleUnixandLinuxLinux最初的初始化系统......
  • 关于C语言输入输出的逗号问题(小细节)
    C语言的输入输出必须要遵循scanf和printf的格式,就是你是什么格式你就要输入什么。一、输入问题#include<stdio.h>intmain(){ inta,b;scanf("%d,%d",&a,&b); printf("a+b=%d",a+b);return0;}编辑 这个程序我们可以看到它运行的结果是错误的!为什么呢,因为我们在s......
  • Vulnhub 靶场 MATRIX-BREAKOUT: 2 MORPHEUS
    前期准备:靶机地址:https://www.vulnhub.com/entry/matrix-breakout-2-morpheus,757/kali攻击机ip:192.168.11.11靶机ip:192.168.11.12一、信息收集及利用1.使用nmap对目标靶机进行扫描发现开放了22、80、81端口。2.80端口访问80端口:查看页面信息没发现什么重要信息,......
  • 基于mediapipe的单人人体骨架细节提取
    MediaPipe是一款由GoogleResearch开发并开源的多媒体机器学习模型应用框架。在谷歌,一系列重要产品,如、GoogleLens、ARCore、GoogleHome以及,都已深度整合了MediaPipe。本文将介绍的为基于mediapipe的人体骨架提取方案。1、mediapipe的安装安装指令如下:pipinstallmed......
  • D :Big Matrix
    湖南省第十八届大学生计算机程序设计竞赛(HNCPC2022)D题原题链接:https://cpc.csgrandeur.cn/csgoj/problemset/problem?pid=1192关于这题其实是一道数学题,如果直接暴力三重循环肯定爆T,所以细心一点的就会发现,其实有规律首先题目意思如下规律如下,自己可以尝试一下列举后面的A(i,j......