Repeat these questions by writing functions

Assignment Help C/C++ Programming
Reference no: EM13163700

Q 2. A 2 dimensional array of doubles has the same number of rows and columns (a square array). Assume the values
are already loaded in the array. Write a loop to calculate the sum total of the elements of the diagonal (the elements
with the same row and column subscript values). In the following example 4x4 2-d array, the elements on the diagonal
are in boldface type. Use the partial declarations given.
12 8 -11 7
6 3 0 2.9
7 7 -11 10
-3 -7 4 8

array< array<double, 4>, 4> mat = { the initial values would go here };
double sum = 0.0;
// write the code

Page 2 of 2 2013-12-09
for (int i(0); i < 4; i++)
sum += mat[i][i];

Q 3. A 2 dimensional array of doubles has the same number of rows and columns (a square array). Assume the values
are already loaded in the array. Write a loop to calculate the sum total of the elements of the anti-diagonal (the
elements whose row and column subscripts add up to the number of rows (or number of columns as they are equal) ?
1). In the following example 4x4 2-d array, the elements on the anti-diagonal are in boldface type. Use the partial
declarations given.

12 8 -11 7
6 3 0 2.9
7 7 -11 10
-3 -7 4 8

array< array<double, 4>, 4> mat = { the initial values would go here};
double sum = 0.0;
// write the code

Q 4. Repeat these questions by writing functions that receive the arrays as constant reference parameters and return
the appropriate values through the function name (via return statement). The function header could look like:
double sumDiag(const array< array<double, 4>, 4> & mat) {
// write the code
} // end function

double sumAntiDiag(const array< array<double, 4>, 4> & mat) {
double sum = 0.0;
for (int i(0); i < 4; i++)
sum += mat[i][3 - i]; // Note: i + (3 - i) = 4 - 1
return sum;
} // end function

Reference no: EM13163700

Questions Cloud

Knowledge of future employer : Explain how knowledge of the evaluator (future employer) should influence a person’s writing of the resume or cover letter
Political-social and cultural issues : What legislation meant to constrain race within prejudicial boundaries was enacted? How did the various groups you researched fight this legislation?
Kotler text-profit marketing strategies : According to Kotler text, what are the primary drivers for applying for-profit marketing strategies to a nonprofit organization?
Part of a surgical admitting process : Part of a surgical admitting process orderlies are available to escort patients to the pre-surgery preparation area. Patients are not allowed to go by themselves as a matter of policy.
Repeat these questions by writing functions : Repeat these questions by writing functions that receive the arrays as constant reference parameters and return the appropriate values through the function name (via return statement). The function header could look like:
Design an object-oriented java application : You are to design an object-oriented Java application to let the user play a dice game that uses two dices. The player bets on a value and the dices roll
Write a java program using the java graphics : Your task for this assignment is to write a Java program using the Java Graphics class to create an example of a computer generated image. This is an opportunity for you to explore computer graphics and exercise some individual creativity.
Identity tangible and intangible benefits of the new payroll : suppose you own a travel agency in a large city you have many clients but growth has slowed somewhat. some long term employees are getting discouraged, but feels that there might be a way to make technology work in favor. use your imagination and sug..
Code skeleton to declare a class named date : Complete the following code skeleton to declare a class named Date. The class should contain variables and functions to store and retrieve a data in the form 4/2/2012.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  During the execution of the above code, how many instru

(a) During the execution of the above code, how many instructions are executed? (b) Assuming a standard unicycle machine (CPI = 1) running at 100 KHz, how long will the above code take to complete?

  Write a function num_digits(n)

C programing, not C++ write a function num_digits(n) that returns the number of digits in a nonnegative integer n.

  Write c program that forks two child processes

Write a C program that forks two child processes. The parent process will print all prime numbers up to 229, the first child process will print the first 50 Fibonacci numbers.

  Write program to declare the array of type float

Write down the c++ program which declares the array of 50 components of type float. Initialize array so that first 25 components are equal to square of the index variable.

  Write program in c to calculate diameter-compression load

Write a program in C to calculate diameter in centimeters of steel rod, an aluminum rod, and a copper rod, which can withstand a particular compression load.

  Prepare an arbitrary sinusoidal waveform

Create a program to compute the derivative of an arbitrary input function, with arbitrary duration and arbitrary limits

  Takes 100 number in an array

Write a program in c++ that takes 100 number in an array and add them and print the sum

  Create a c++ console application

Objective: Create a C++ console application that will model the characteristics of a resistor. Create a multifile project. Create and add to the project an h file containing the resistor-class definition. Create and add to the project a cpp file cont..

  Write program that stores the numbers in array

Write a c++ program that stores the following numbers in the array named miles: 15,22,16,18,27,23, and 20. have your program copy the data stored in miles to another array.

  Define a structure to store marks of a student

Define a structure to store roll no, name and marks of a student - using the structure of Q2. a), above write a 'C' program to create a file "student.dat". There must be one record for every student in the file.

  Project

Unit 3 Individual Project SSCI210 – 1304B – 01 A typical individual who commits who commits hate crimes whether it is against or aimed at the Gay/lesbian community , the persons of color or the Jewish community, ( I mention these three because they a..

  Create a template class

Create a template class, SVector, that implements a constructor

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