alejandr1872913
12.03.2021 •
Chemistry
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*,int,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;
}
Solved
Show answers
More tips
- S Style and Beauty Is Photoepilation the Solution to Unwanted Hair Forever?...
- O Other What is a Disk Emulsifier and How Does it Work?...
- F Family and Home What does a newborn need?...
- F Family and Home Choosing the Right Car Seat for Your Child: Tips and Recommendations...
- F Food and Cooking How to Get Reconfirmation of Registration?...
- C Computers and Internet How to Get Rid of Spam in ICQ?...
- A Art and Culture Who Said The Less We Love a Woman, the More She Likes Us ?...
- F Family and Home How to Get Rid of Your Neighbors?...
- S Society and Politics How Could Nobody Know About the Dead Mountaineers?...
- H Health and Medicine How to Cure Adenoids?...
Answers on questions: Chemistry
- C Chemistry If a sodium atom looses an electron to form an ion what is its charge?...
- C Chemistry Which property do gas particles at the same temperature share? a.) potential energy b.) pressure c.) average kinetic energy d.) volume...
- C Chemistry What is the effect of the concentration of solute (expressed in molality, m) on the freezing point of the solution?...
- C Chemistry For each Atom or ion indicate how many electrons protons and neutrons...
- M Mathematics Is this a function? (it says the question has to b at least 20 characters long, sorry)...
- M Mathematics Sub and you get too live Huggablesheep89...
- H History Why did Pope Urabn think Christians should win?...
- M Mathematics A water reserve follows the path given by y=2x+20, where each unit represents 1 kilometer. A town is located at (50, 5). The town’s laws require that the water reserve...
- E English How do you think your friendships have been affected by digital devices and social media?...
- E English Even though they have different ways of getting food, mantis shrimp and great white sharks are (hard, vicious, small, or spiny) both predators....
Ответ:
give me like and follow up
Ответ: