Develop a program that prints out the sum

Assignment Help Programming Languages
Reference no: EM132401587

Multi-Dimensional Arrays

Exercise #1: Develop a program that prints out the sum of each column of a two-dimensional array. The program defines method sumColumn() takes a two-dimensional array of integers and returns a single-dimensional array that stores the sum of columns of the passed array. The program main method prompts the user to enter a 3-by-4 array, prints out the array, and then calls method sumColumns(). Finally, it prints out the array retuned by method sumColumns(). Document your code, and organize and space the outputs properly as shown below. C++ students: instead of asking the user for input, you must read it from a file. See appendix for more information.

Sample run 1:

Enter a value: 9
Enter a value: 1
Enter a value: 2
Enter a value: 4
.
.
.
Enter a value: 3

The entered matrix:
9 1 2 4
2 2 8 0
3 3 3 3

Sum of column 0 is 14
Sum of column 1 is 6
Sum of column 2 is 13
Sum of column 3 is 7

Sample run 2:

[SIMILAR FORMAT OF INPUT ABOVE, BUT DIFFERENT NUMBERS]

The entered matrix:
10 10 10 10
1 1 1 1
50 50 50 50

Sum of column 0 is 61
Sum of column 1 is 61
Sum of column 2 is 61
Sum of column 3 is 61

Exercise #2: Develop a program that prints out the location of the largest value in a two-dimensional array. The largest values may appear more than once in the array, so you must only print out the first instance. The program defines method locateLargest() that takes a two-dimensional array of integers and returns the location (row index and column index) of the first largest value as a single-dimensional array. The program main method prompts the user to enter a 3-by-4 matrix, prints out the matrix, and then calls method locateLargest(). Finally, it prints out the array returned by method locateLargest(). Document your code, and organize and space the outputs properly as shown below.

Sample run 1:

[SIMILAR FORMAT OF INPUT ABOVE, BUT DIFFERENT NUMBERS]

The entered matrix:
9 1 2 4
2 11 18 20
3 20 3 12

First largest value is located at row 1 and column 3

Sample run 2:

[SIMILAR FORMAT OF INPUT ABOVE, BUT DIFFERENT NUMBERS]

The entered matrix:
19 11 22 44
29 51 81 20
23 90 45 90

First largest value is located at row 2 and column 1

Sample run 3:

[SIMILAR FORMAT OF INPUT ABOVE, BUT DIFFERENT NUMBERS]

The entered matrix:
89 11 22 44
29 51 80 20
33 10 45 10

First largest value is located at row 0 and column 0

Exercise #3: Develop a program (name it AddMatrices) that adds two matrices. The matrices must of the same size. The program defines method Addition() that takes two two-dimensional arrays of integers and returns their addition as a two-dimensional array. The program main method defines two 3-by-3 arrays of type integer. The method prompts the user to initialize the arrays. Then it calls method Addition(). Finally, it prints out the array retuned by method Addition(). Document your code, and organize and space the outputs properly as shown below.

Sample run 1:

Matrix A:
2 1 2
7 1 8
3 20 3

Matrix B:
1 1 1
1 1 1
1 1 1

A + B:
3 2 3
8 2 9
4 21 4

Sample run 2:

Matrix A:
2 2 2
2 2 2
2 2 2

Matrix B:
2 2 2
2 2 2
2 2 2

A + B:
4 4 4
4 4 4
4 4 4

Instructions:

1. Programs must be working correctly.
2. Programs must be completed and checked before working the assignment.
3. Programs must be checked by the end of the designated lab session.

Appendix - Referencing row or column length
C#
int[][] grid = new int[4][5];

To get the row length use arrayname.GetLength(0)
E.g.: grid.GetLength(0)

To get the column length use arrayname.GetLength(1)
E.g.: grid.GetLength(1)

Java:
int[][] grid = new int[4][5];

To get the row length use arrayname.length
E.g.: grid.length

To get the column length use arrayname[0].length
E.g.: grid[0].length

Appendix for C++ Students

One of the most common (and simplest) file formats for storing data is "comma separated values" - or .csv files. You can make these in Microsoft Excel or something even simpler like Notepad or TextEdit. They look like this:

1, 2, 3
4, 5, 6
7, 8, 9

Each data element is separated from the others by comma; note that there's no comma at the end of the line.

You've probably used getline a lot now, but there's a variation of it that you probably haven't used. If we pass it three parameters instead of two, the third represents the "delimiter" between the data elements which, in this case, is the comma. However, getline gives us a string, not a number - so we have to convert it to a number using "stoi" (or "string to int"). The code below reads from a file called "matrices.csv" which is located in the "Debug" folder of the project (so it can be found). Note: make this file before coding.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
void main() {

// Create a filestream object - just like last lab.
fstream fs;
// Open the file for reading using "in".
fs.open("matrices.csv", fstream::in);
// When we read in from a file, it's a string (s).
// We have to convert that string to a number (i).
string s; int i; int sum = 0;

// While we can read a row/string from the file... continue processing each row

while (getline(fs, s, ',')) { // Get the first string, reading up until a comma (1st)
i = stoi(s); sum += i; // Convert it to an int and add to sum
cout << i <<"|"; // Print it out
getline(fs, s, ','); // Get the next value, reading until a comma (2nd)
i = stoi(s); sum += i; // Convert it to an int...
cout << i << "|"; // Print it out
getline(fs, s); // Get the remainder of the string (3rd)
i = stoi(s); sum += i; // Convert it to an int...
cout << i << endl;
}
cout << sum << endl;
// Close the file
fs.close();
cin >> s;
}

Verified Expert

The task of the assignment is to develop 3 C# programs that test the functionality of the Multi-Dimensional Arrays.Program 1 requires to determine sum of values in each column.Program 2 requires to determine the location of row and column with largest value.Program 3 requires to determine sum of two matrices.The code is well commented and the output is well documented.

Reference no: EM132401587

Questions Cloud

What is the test statistic for the hypothesis test : Suppose that in a random selection of 100 colored candies 22% of them are blue the candy company claims that the percentage of blue candies
What is the sample size needed to estimate a mean : What is the sample size needed to estimate a mean to within +-5 with 95% confidence if the standard deviation is assumed to be 18?
How your organization can foster career development : Explain how your organization can foster career development of its employees as well as how you will keep employees motivated
Describe the structure and function of the sector : The purpose of this research project is to provide you the opportunity to demonstrate your mastery of the course materials and information presented throughout.
Develop a program that prints out the sum : CSE 1321L: Programming and Problem Solving Lab - Develop a program that prints out the sum of each column of a two-dimensional array
How you will use what you learned as a teacher : Attend a school board meeting for a local school district. If you are unable to attend in person, you may watch a live stream or an official recorded video.
Propose an initiative for an educational issue : In a 500-750-word "Letter to the Editor," propose an initiative for an educational issue that you feel needs to be addressed. Include a plan about.
Who will need to be contacted regarding isla suspension : Who will need to be contacted regarding Isla's suspension? What services, if any, need to be provided to Isla during her removal to an interim alternative.
How you would plan to use the knowledge in the classroom : Write your opinion of the article; and if you found anything new or interesting. Describe how you would plan to use this knowledge in the classroom.

Reviews

Write a Review

Programming Languages Questions & Answers

  Create program to enter expenses for the month

Create a program which asks the user to enter amount that he or she has budgeted for month. (For example: $2,000.00) A loop must then prompt the user to enter each of his or her expenses for month.

  Reservations system to be horizontal or vertical application

Top Sail Realty Situation: Top Sail Realty is one of the largest time-sharing and rental brokers for vacation cottages. Do you consider the reservations system to be a horizontal or a vertical application? Give reasons for your answer.

  Program that calculate the average of a group of test scores

Write a program that calculate the average of a group of test scores, where the lowest score is dropped. It should use the following functions: void getScore() - should ask the user for a test score, store it in a reference parameter variable, and..

  Creating a program that works as a grammar checker

My project is about creating a program that works as a grammar checker for Arab students of age 15+. I’m not asking you to create a grammar checker from the scratch, but you will be given bellow the mistakes that needs to be corrected.

  How many time is loop body of while statement executed

How many time is the loop body of the while statement executed? a) once, b) never, c) 49 times, d) 50 times, e) until a number 50 or larger is entered

  Using unix extract the various ethnic populations in file

Using Unix extract the various ethnic populations in your file.

  Median-of-medians algorithm partitions input into groups

Median-of-medians algorithm to solve selection problem. Complete following exercises. Median-of-medians algorithm partitions input into groups of 5 elements, but it also works if we partition input into groups of 7.

  Write program to enter name-number of planet from sun

Write down the program which permits the user to enter name of planet, and then prints message stating that planet's number when counted outward from sun.

  Create a method to handle user input

Write a program that uses an array to find the Average of 10 double values. Create 1 method to handle user input. Create 1 method to sum and output average.

  Building a hybrid mobile application using Ionic Framework

Building a hybrid mobile application using Ionic Framework. The main idea of the app is to help a user find information and exchange ideas

  Designing system to handle donations of non-profit agency

You have been hired by worldwide non-profit agency to create a system to handle their donations.

  The code to implement a state diagram to recognize

The code to implement a state diagram to recognize one form of the comments of the C-based programming languages, those begin with /* and end with */.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd