subject
Chemistry, 12.03.2021 15:50 Arealbot

Solve code for C++: #include
using namespace std;
//You need to implement two functions below.
//Function 1: 25 points
bool exists_trio(int*,int);
//Input:
//an integer array (param 1) and its size (param 2)
//Output:
//True or false
//Behavior:
//Returns true is there exists
//a sequence of 3 *consecutive* values in the array
//such that the sum of the first two elements
//is equal to the third element in that
//sequence, false otherwise.
//Example:
//For the array {3,4,1,3,17,3,20,21,5,96},
//the function returns true because of the
// sequence {17,3,20} (i. e., 17+3=20).
//For the array {3,4,1,3,3,7},
//the function returns false.
//Function 2: 25 points
bool exists_trio_within_distance(int*,in t, int);
//Input:
//an integer array (param 1), its size (param 2), and
//a distance (param 3)
//Output:
//True or false
//Behavior:
//Returns true is there exists
//a sequence of 3 values in the array
//such that sum of the first two elements
//is equal to the third element in the
//sequence. The third element has to be
//within a distance of dist from the
//second element.
//False otherwise.
//Example:
//For the array {3,4,1,3,17,3,96,21,5,20},
//if dist is 7
//the function returns true because
// 4+1=5 and the element 5 is within 7 spots
//from element 1.
//For the array {3,4,1,3,3,7},
//if dist is 2,
//the function returns false.
//This is because, even though 3+4=7,
//element 7 is not within a distance of 2
//from element 4.
int main()
{
int asize=10;
int a[asize]={3,4,1,3,17,3,20,21,5,20};
int bsize=6;
int b[bsize]={3,4,1,3,3,7};

//test exists_trio function
//should print "A trio exists."
if (exists_trio(a, asize))
cout << "A trio exists.\n";
else
cout << "A trio does not exist.\n";
//should print "A trio does not exist."
if (exists_trio(b, bsize))
cout << "A trio exists.\n";
else
cout << "A trio does not exist.\n";
cout << "\n";

//test exists_trio_within_distance function
//if you only want to test exists_trio, comment
//out the below code
//change the array a to help test Function 2
a[6]=209; //change a[6] from 20 to 209
int dist=7;
//should print "A trio exists within distance 7."
if (exists_trio_within_distance(a, asize, dist))
cout << "A trio exists within distance " << dist << "." << endl;
else
cout << "A trio does not exist within distance " << dist << "." << endl;
dist=2;
//should print "A trio does not exist within distance 2."
if (exists_trio_within_distance(b, bsize, dist))
cout << "A trio exists within distance " << dist << "." << endl;
else
cout << "A trio does not exist within distance " << dist << "." << endl;
}

ansver
Answers: 2

Another question on Chemistry

question
Chemistry, 22.06.2019 05:40
Salicylic acid is a very important acid. it is used to synthesize the aspirin by treating with acetic anhydride. a 0.2015-g sample of salicylic acid was dissolved in a 100.00-ml volumetric flask, and the solution was diluted to the mark. a 10-ml aliquot of this solution was titrated with standard naoh (0.01130 + 0.2% n) to a phenolphthalein faint pink color end point at 19.81 ml. (a) (calculate the normality of the salicylic acid solution used in the titration. (b) assuming the salicylic acid is pure, what is the equivalent weight of the salicylic acid? practice problems for the final exam (continued) (c) (calculate the inherent error in the determination of the equivalent weight you calculated in part (b). use the following absolute errors in the equipment /glassware when calculating the inherent error. 5.00-ml pipet: + 0.02 ml 100-ml volumetric flask: + 0.08 ml analytical balance: + 0.2 mg 25-ml buret: + 0.03 ml
Answers: 2
question
Chemistry, 23.06.2019 06:30
The polarity of an oxygen-hydrogen bond is higher than the polarity of a nitrogen-hydrogen bond, allowing amines to be more soluble than alcohols.
Answers: 3
question
Chemistry, 23.06.2019 07:30
Type the letter that represents the correct location for each particle type below. the neutron is found at __ the electron is found at __ the proton is found at __
Answers: 1
question
Chemistry, 23.06.2019 18:00
The mass of an object will be the same on the earth as it is on the moon. need asap
Answers: 3
You know the right answer?
Solve code for C++: #include
using namespace std;
//You need to implement two function...
Questions
question
Mathematics, 31.01.2021 19:50
question
English, 31.01.2021 19:50
question
Mathematics, 31.01.2021 19:50
Questions on the website: 13722363