0 Up votes0 Down votes

3 views4 pagesProject 9

Nov 13, 2014

© © All Rights Reserved

PDF, TXT or read online from Scribd

Project 9

© All Rights Reserved

3 views

Project 9

© All Rights Reserved

- Matlab Avance
- maths_cheat_sheet.pdf
- UT Dallas Syllabus for eco5309.501 05f taught by Daniel Obrien (obri)
- Arch 1
- Foreign Donor Money in USA Elections
- g 05313347
- Cece Matlab Intro1
- Attachment
- WS Schulzki
- c Questio
- Chapt_02_Lect04 (1)
- 07 GENN004m Matrices
- MathForEE
- MATRICES.doc
- Rancangan-Tahunan-Matematik-2012
- data-driven-parallel-scheduling.pdf
- 304 Matrix
- Matrix Methods - Applied Linear Algebra 3rd Ed - Bronson,Costa.pdf
- 13_799.pdf
- Nonlinear

You are on page 1of 4

Fall 2014

Programming Project #9

Assignment Overview

You will create a sparse matrix data structure using an underlying STL map and overload

various binary operators to exercise the data structure

This assignment is worth 50 points (5.0% of the course grade) and must be completed

and turned in before 11:59PM on Monday, Nov 17th . This is two weeks because of the

midterm on Nov 6th.

Background

A sparse matrix is a regular mathematical matrix where most of the elements have a 0

value. They are often used in science and engineering applications (see

http://en.wikipedia.org/wiki/Sparse_matrix ). Because they have 0's as most of the values,

special data structures and algorithms are required to be efficient in their use.

A Different Specification

The specification for this project will be a little different. In the past we have provided

both a main and a header file. From now on we will only provide the main. Your job is to

design the class to meet the specifications as provided by the main and that meets the

notes below.

One file

What you will turn in is a single file that contains the class declaration and the definitions.

If you need examples of how to do that, look at worksheets 14 and 15. This makes the

grading process easier. No other reason than that.

Updated 11/6. You will turn in two files: class-09.h and class-09.cpp Handin will allow

turning in both files.

Specifications

the underlying data structure will be a map. It will map a pair<long,long>

(representing the row,column address respectively) to a long .

constructors

o two arg: two longs indicating the number of rows and columns respectively.

SparseMatrix mat(100,50) makes mat with 50 rows each with 100

colums 100 rows with 50 columns each

o three arg: two longs indicating row and column, and an initializer list of longs.

The longs come in triples where each triple indicates: row, column, value to

be set in the matrix. SparseMatrix

mat2(5,5,{1,1,100,2,2,200}) makes mat2 a 5x5 matrix with the

value at 1,1 set to 100 and the value at 2,2 set to 200

operator(row,col) . Takes two args (row,col) and returns a long.

o The two argument longs indicate row and column and return either 0 or, if the

location's value has been set, the value. mat(1,1) will return either a 0 or

the value set at 1,1.

o You could overload a subscript operator (operator[]) but only with one

argument, the index of the element. If you want two indicies like

(row,column), you overload operator(). This operator is usually

interpreted as the function operator, but for now it will be the accessor

function. Note: It cannot be used to set a value, only return it.

.set(row,col,val) method. Takes 3 args: row, column and value. No return.

o Sets the value of the matrix at location row,column to value.

.dimensions() method. No args, returns a pair<long,long>

o returns the dimension (the row and column size) of the matrix

.element_count() method. No args, returns a long

o returns the number of non-default values in the matrix

Operations supported

addition between two matrices. Example shown below

addition between a matrix and a long.

o Should be commutative: 5 + mat == mat + 5

o Note: we make the decision that, for scalar addition, we only modify the

non-default values. Could be done differently, but that is what we do here.

multiplication between two matrices. Example shown below

multiplication between a matrix and a long

o should be commutative as addition with long

o since the default value is 0, the only values potentially changed are the

non-default values

printing. Should be able to print using cout << mat << mat2 <<endl;

o only non-default values are printed

o those values are printed in order

smallest row first

within the row, smallest column first

Errors

Certain errors require that you throw an exception. We cover exceptions in lab10 this

week. Summary, throw a runtime_error if you run into any of the following issues:

matrix-matrix addition requires that the two matrices have the same dimensions, the

same row and column size

matrix-matrix multiplication require that the row column size of the first matrix have

the same size as the column row size of the second matrix

Anything else you need!!!

You are defining your class, so any other functions/members you might need, feel free to

add them. The test will only involve using the main provided.

Important things to Note

1. You should try to make your code efficient. One of the things you learn is that

efficiency should come after you get the thing to work. So getting it to work should

be the most important goal. But afterwards, think about how to make it more efficient.

If you have a 1000x1000 matrix (106 elements) and only 1000 non-default values (say

the identity matrix), it would be wasteful, though not incorrect, to do 106 adds or 106

multiplies to find the answer.

a. it's easier to be efficient with adds, much easier, than with multiplies.

2. Don't worry about any of the errors to begin with. Write correct code and see if it runs

Add Matricies

Take a look at http://en.wikipedia.org/wiki/Matrix_addition

matrix + matrix

matrix + scalar

o adds the scalar to every element of the matrix.

o Remember, for our SparseMatrix, we only modify non-default values

1 2

6

7

3 4 + 5 = 8

9

5 6

10 11

Multiply Matricies

See http://en.wikipedia.org/wiki/Matrix_multiplication

matrix * long

matrix * matrix

Multiply Matricies

Deliverables

class-09.cpp and class-09.h -- your source code solution and your header

file will be required to solve the problem.(remember to include your section, the date,

project number and comments). Remember, you do not provide main-09.cpp

1. Please be sure to use the specified file names

2. Save a copy of your file in your CSE account disk space (H drive on CSE

computers).

3. You will electronically submit a copy of the file using the "handin" program:

http://www.cse.msu.edu/handin/webclient

Assignment Notes

- Matlab AvanceUploaded byyimmy
- maths_cheat_sheet.pdfUploaded byDaniel Smith
- UT Dallas Syllabus for eco5309.501 05f taught by Daniel Obrien (obri)Uploaded byUT Dallas Provost's Technology Group
- Arch 1Uploaded bypathak_5611960
- Foreign Donor Money in USA ElectionsUploaded byJoshua J. Israel
- g 05313347Uploaded byIOSRJEN : hard copy, certificates, Call for Papers 2013, publishing of journal
- Cece Matlab Intro1Uploaded byRashad
- AttachmentUploaded byDaksh Oswal
- WS SchulzkiUploaded byRenzo PO
- c QuestioUploaded byRohit Minni
- Chapt_02_Lect04 (1)Uploaded byLannon Adamolekun
- 07 GENN004m MatricesUploaded byBishoy Emile
- MathForEEUploaded byvinodlife
- MATRICES.docUploaded byVizet
- Rancangan-Tahunan-Matematik-2012Uploaded byLow Eng Han
- data-driven-parallel-scheduling.pdfUploaded byMarci Frederick
- 304 MatrixUploaded bybuckk138
- Matrix Methods - Applied Linear Algebra 3rd Ed - Bronson,Costa.pdfUploaded byaufal Riswan
- 13_799.pdfUploaded byAnasNahidh
- NonlinearUploaded byshimic32000
- Week3 HomeworkUploaded byyashar2500
- Vectors and MatricesUploaded bydorathi
- Final 211 So LutUploaded bySarkhan Hashimov
- Vissim Training - 12. Dynamic RoutesUploaded bySulastri Sitakar
- Bai-Tap-buoi-1-B.pdfUploaded byDang Cong San
- Matlab Notes Part1Uploaded byWilliamDaugas
- GATE-CSUploaded byviddusagar
- MathematicsUploaded byAyush Gochhayat Gochhayat
- MatricesUploaded bySonu Kale
- guigvbUploaded byrajalaxman

- Spoken English_ Flourish Your Language ( PDFDrive.com )Uploaded byumeshamy
- Petazzoni Device Tree DummiesUploaded byNelson Kigen
- 8182473489Uploaded bykabirakhan2007
- 3G Tariff Plans, Best 3G Plans, Airtel Internet 3G PacksUploaded byumeshamy
- Google Patented CfarUploaded byumeshamy
- Stanford cs106L book c++.pdfUploaded bylantea1

- Soalan Fault Finding_PKM_2011.pdfUploaded byAzman Ahmad
- 70-765.pdfUploaded byHawkins Chin
- 20190227_12.txtUploaded byJannah Wala
- HCI Technical RecruiterUploaded bysrimkb
- Intercom List as on 1- April- 2015Uploaded byUday Kumar
- 2 Hypothesis TestingUploaded byfais_38
- Orifice FlangesUploaded bydediekos
- Functional Resume SampleUploaded byLex
- Managing Employee PerformanceUploaded byDonasian Mbonea Elisante Mjema
- 3340-Lectures-7-to-12-S1-2015Uploaded byUtsav Koshti
- FRICTION STIR WELDING OF AA6082 BY USING STRAIGHT THREADED TOOL BY VARYING SPEEDSUploaded byInternational Journal for Scientific Research and Development - IJSRD
- U.S. ARMY COUNTERINSURGENCY FORCES, DEPARTMENT OF THE ARMY FIELD MANUAL FM 31-22, NOVEMBER 1963Uploaded byDeclassifiedMatrix
- cat 11 Rev 7+_webUploaded byvinnman87
- William Allan Kritsonis, PhD - Curriculum Vita, 2016Uploaded byAnonymous sewU7e6
- DPAR FLUIDIZATIONUploaded byLouie G Navalta
- decent work indicatorsUploaded byximeres
- L14F1/L14F2Uploaded byMicrotech Solutions
- EXAMPLE OF VISUAL BASIC PROJECTSUploaded bySyahid Muhammad
- Lect5 Power dfgjh djhd jUploaded byRahul Shandilya
- Som AssignmentUploaded byRohit Rai
- Nantuckets Nectar 2 & 3Uploaded byMayor
- HR Finals DigestUploaded byAnonymous NqaBAy
- Apprentices DeedUploaded byPankaj Mahatha
- 2013-2014-General-Cat-smUploaded byMoustaffa
- Micro Eco IaUploaded byelizabeth
- BageshwarUploaded byRahul Singh
- Eloqua Benchmark Report - Summary 3Q10Uploaded byJoe Chernov
- MM FI GR LIV POUploaded byindiannewton
- Electronics Keralam_ CIRCUITSUploaded byMnichandra
- Kasravi Applications of TRIZ to ITUploaded bydejawi

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.