C++ programs that compute the agreement for two vectors

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

Programming Assignment

The agreement for two binary vectors A and B, each of size n+1, is defined as the following:
int sum=0; for (int i=0; i<=n; i++) if (A[i]==B[i]==1) sum++; (Calculation 1)

In this assignment, you write C++ programs that compute the agreement for two given vectors (see Calculation 1 above). In these programs, in vectors A and B only nonzero elements (elements that are 1) are stored. We give you a function that generates input for a test case for your programs. Both correctness and efficiency of your programs are important.

Please see Attachment #1 for this assignment. However, you implement a linked list version of the program started in Attachment #1, which uses arrays. That is, instead of an array, you use linked lists to store the non-zero elements of the vectors. This involves changing struct definition to include a link, and writing a new agreement() function. Keep the same input vectors, but you need to write a new generate_row_and_col() function to create linked lists.



YOUR WORK IS DUE 11:59PM ON THURSDAY, SEP. 11.


/* ATTACHMENT 1: */

#include <stdio.h>
#include <iostream.h>

/*
For Assignment #2
You are asked to write a function that calculates the agreement for two vectors, a row and a column

Normally this agreement can be calculated as follows:
int sum=0; for (i=0;i<=n; i++) if (A[i]==B[i]==1) sum++;
(Calculation 1)
But, you will need to do it differently since zeros are not stored in vectors

function generate_row_and_col() below is provided only for testing. Your function should not be designed for a fixed pair of row or column vectors;
row is a row vector of size at most n,
col is a (column) vector of size at most n,

each of these vectors stores only 1's

here we use an array to store the indices at which the element is 1

e.g. for row vector [0,0,1,0,0,1,0], which has 1's at indices 2, and 5, respectively
row[0]=2;
row[1]=5;
row[2]=-1 (-1 in x marks the end of non-zero elements in row)

Please note that all other elements (not stored in row) are zeros

Similarly let col be the following vector [0,0,0,0,0,1,0], then
col[0]=5;
col[1]=-1;

For this pair of row and col, the agreement is 1, because row[1]=col[0]=5, and all other terms in Calculation 1 (see the top of the page) are zeros
*/

static const int n=1000; /* vector size limit */

struct element {
int x; /* original index of non-zero array element */
int val ; /* integer non-zero value at index x */
} ;

int row[n] ;
int col[n] ;

int i;

void generate_row_and_col() {
for (i=1; i<n/4; i++) row[i]=4*i;
row[0]=1;
row[n/4]=-1;
for (i=1; i<n/5; i++) col[i]=5*i;
col[0]=1;
col[n/5]=-1;
}

int agreement()
{
/* calculate the agreement for row and col;
output the result
*/

}

int main()
{
generate_row_and_col() ;

agreement();
return 0;}

Reference no: EM13300279

Questions Cloud

Calculate the radiation pressure on the mirror : A 25.5-mW laser beam of diameter 2.08 mm is reflected at normal incidence by a perfectly reflecting mirror. Calculate the radiation pressure on the mirror
Type of sport is factor in elite athletes resting heart rate : A study comparing the resting heart rate of four different types of elite athletes recruited: 10 cyclists, 10 triathletes, 10 soccer players, and 10 baseball players. The resting heart rate of each athlete was measured, and the following hypothesis w..
What force is required to stretch the spring by this amount : A load of 52.5 N attached to a spring hanging vertically stretches the spring 5.29 cm. What force is required to stretch the spring by this amount
What is the stress along the top edge and the bottom edge : A horizontal pre-stressing force of 500kN is applied to rectangler beam. the beam has a depth of 500mm and a width of 250mm. the force is applied at a distance of 80mm below the x-x axis.
C++ programs that compute the agreement for two vectors : In this assignment, you write C++ programs that compute the agreement for two given vectors (see Calculation 1 above). In these programs, in vectors A and B only nonzero elements (elements that are 1) are stored. We give you a function that gen..
Hat will be the property tax bill on this property : A residence in Jefferson County has an assessed value of $140,000. Its owner qualifies for an old age exemption of $8,000 and a homestead exemption of $18,000. The property tax rate is $5 per $100 AV. What will be the property tax bill on this pro..
Why do we focus on cash flows rather than net income : Why do we focus on cash flows rather than net income in capital budgeting? Is operating cash flow the same as EBITDA (Earnings before interest taxes, depreciation and amortization)?
What is the fractional change in length : Most materials will expand when the temperature is increased. The change in size will depend on several factors, including the original size, What is the fractional change in length
Wedding planning issued : Bridezilla Wedding Planning issued two checks totaling $150,000 to BabyCakes Bakery for wedding cakes it had purchased. BabyCakes Bakery endorsed the checks over to the law firm of Shark & Shyster as payment for a retainer.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Calculates the sum of the cube roots of two integers.

Wrtie a program that calculates the sum of the cube roots of two integers. The program should use the following functions as well as a main funcion. 1) enter one positive value 2) compute the cube root of one integer 3) report the value of two intege..

  Write a class volumeofbox that calculate the volume

write a class VolumeOfBox that calculate the volume by this formula : length * breadth *

  Prefetching is a technique that leverages predictable

Prefetching is a technique that leverages predictable address patterns to speculatively bring in additional cache blocks when a particular cache block is accessed. One example of prefetching is a stream buffer that prefetches sequentially adjacent..

  The factorial of a positive integer n, denoted by n!

Write a program that computes the sequence of factorial values: 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, ....

  An expression whose value depends upon the evaluation

Give an example in C++ of an expression whose value depends upon the evaluation order. Show the orders that produce different values and the values they produce. Explain what side effect is the expression contains.

  We base our need to implement composition upon

What criterion, or criteria, should be used to include objects of a class as data members of another class? In other words, what should we base our need to implement composition upon?

  Create an array of objects from the provided code

Create an array of objects from the provided code and run a for loop to assign strings and numbers. In this assignment, I will need to see the main function. Make sure there is a default constructor.

  Input parameters, and returns nothing

Write a function called ten2one(), that takes no input parameters, and returns nothing (void). The body of the function must include a loop that counts from 10 down to 1, printing the count value each time in the loop. The output should look like (no..

  When given a c-string reference and a character

Write a program that implements and tests the following functions for use with C-strings (you may assume that  input obtained by the program is limited to a maximum of 80 characters):

  Loops and if conditions

Write a program that requests a password

  To use a sentinel loop so once the value of -99 i

modify this program to use a sentinal loop so once the value of -99 is entered after getting the pay and hours the program should end.

  Writing a program that creates a linked list

Writing a program that creates a linked list from 100 randomly generated numbers and sorts the using a heap. One heap in ascending order and one heap in descending order. Then displays the original linked list and both sorted lists.

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