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

  Program to compute surface area of sphere using function

Write down a program in C++ to compute surface area of sphere using a function. As sample run, write down the surface areas of spheres with radii.

  Program to compute the total volume

Write a program to compute the total volume for a number of cylinders. A cylinder may have different values for height and radius.

  Use a define statement to create a constant

Follow these specifications: Use a define statement to create a constant that will hold your student number. You should have separate string variables for your first and last name; name these first_name and last_name.

  Writing function that computes leap years

Write down function that computes leap years. Function prototype is as follows: Write function body which returns true if year is a leap year and false if year is not a leap year.

  Const int num_years

How do you get this program to get both player input and then display results(As described on bottom) #include  const int NUM_YEARS=15;//The number of years const int NAME_SIZE=32;//The max size of the player name string

  Maze program

Maze program. In this assignment you will represent a maze with a binary tree. . The starting point is node N and the ending point is node Z.

  What constructors do and when they are executed

Explain what constructors do and when they are executed. Explain the two types of constructors. Provide an example class that includes both types of constructor functions and demonstrate how an object would be instantiated using both types of constru..

  Why does the neverwet spray protect it from water

As is know, acetone is a polar molecule like water, so isn't it suppose to mix? So my question is: why does the Neverwet spray protect it from water but not from oils and detergents?

  Write a program that asks the user to enter the names of 3

Write a program that asks the user to enter the names of three salesmen. The program should thenaccept the sales produced for salesman for each quarter of the year. Display the name, and the totalsales amount, of each salesman.

  Determine the meaof the numbers in the array

Determine the mean(average) of the numbers in the array, and output the reslt. Use a subprogram to input the numbers, a function to find the mean.

  Program to compute and show miles per gallon

Create the program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and show miles per gallon.

  Design class for textbook-data field for grade level of book

Design a class named TextBook that is child class of Book. Include new data field for grade level of book. Create a displayTextBookInfo () method so that you can accommodate new grade-level field.

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