Question

In C++ Please for both questions and thank you!

Write a predicate function named isEqual that is passed in 2 vectors of integers and returns true if the vectors are equal, otherwise returns false

Two vectors are equal if they have exactly the same values, all in exactly the same location within the vector.
You may not use the overloaded vector operator ==, since that is the functionality you are to reproduce.

Hint:
At what point in your solution can you determine (and return) the fact the vectors are not equal?
At what point in your solution can you determine (and return) the fact the vectors are equal? zyBooks Library cs 10 home 9.6: ICE 8 is Equal vectors Write a predicate function named isEqual that is passed in 2 vectors of integers and returns true if the vectors are equal, otherwise returns false Two vectors are equal if they have exactly the same values, a in exactly the same location within the vector. You may not use the overloaded vector operator since that is the functionality you are to reproduce. Hint At what point in your solution can you determine (and return) the fact the vectors are not equal? At what point in your solution can you determine (and return) the fact the vectors are equal? ACTIVITY 9.6.1: ICE 8 isEqual vectors main.cpp Load default template... 1 include iostream> 2 FIXME include appropriate library 4 using namespace std; 6 FIXME declare and implement isEqual function 8 int main() 10 //Leave main function empty JUST declare and implement isEqual function above. 11 12 return 0 13

Get a sentence from the user using getline.

Convert all lowercase characters to uppercase characters.

Output the converted sentence.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program1:


#include <iostream> // cout
#include <algorithm> // equal
#include <vector> // vector
using namespace std;
bool isequal (int p, int q) //predicate function isequal

{
return (p==q);
}

int main () {
int vector1[] = {10,40,50,80,120}; // vector1: 10 40 50 80 120
vector<int>vector2 (vector1,vector1+5); // vector2: 10 40 50 80 120

// using default comparison:
if ( equal (vector2.begin(), vector2.end(), vector1) )
cout << "The two vectors are equal.\n";
else
cout << "The two vectors are not equal.\n";

vector2[3]=81; // vector2: 10 40 50 81 120

// using predicate comparison:
if ( equal (vector2.begin(), vector2.end(), vector1, isequal) )
cout << "The two vectors are equal.\n";
else
cout << "The two vectors are not equal.\n";

return 0;
}

>II cout 2 #include <iostream» 3 #include <algorithm» //equal 4 #include <vector> 5 using namespace std; 6 bool isequal (int

Output:

The two vectors are equal The two vectors are not equal.

Program2:

//header files
#include <cctype>   
#include <iostream>
using namespace std;
int main()
{

char stn[ 100 ]; //declare and initialize the array

cout << "Enter the sentence: ";
cin.getline( stn, 100 ); //getline function
   for(int i=0;stn[i];i++)
   {
       if (islower(stn[i]))
       {
       stn[i] = toupper(stn[i]); // converted the sentence from lower case into upper case
       }
   }


// Print the converted the sentence
cout << "Converted sentence is : "<<stn << endl;

return 0;
}

Code screen:

1 //header files #include <cctype> 3 #include <iostream» 4 using namespace std; 5 int main() 7 8 char stn[ 100 l; //declare a

Output:

compiled and executed in 8.053 second(s Enter the sentence: apple box cat dog Converted sentence is APPLE BOX CAT DOG

Add a comment
Know the answer?
Add Answer to:
In C++ Please for both questions and thank you! Write a predicate function named isEqual that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (c++) Write a predicate function that checks whether two vectors have the same elements in the...

    (c++) Write a predicate function that checks whether two vectors have the same elements in the same order. Write a predicate function that checks whether two vectors have the same elements in the same order bool equals(vector<int> a, vector<int> b) provided code : #include <iostream> #include <vector> using namespace std; bool equals(vector<int> a, vector<int> b) { // TODO } int main() { // TODO // Print Expected, "Vectors a and b are " (print "equal." if they are. Otherwise, print...

  • You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function...

    You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function into a file named Q1.cpp. Q1.cpp should only include your function implementation, the necessary #include directives if needed, and should not contain anything else such as the main function or global variable declarations. Test your code using a separate main.cpp file where you implement a sufficient number of test cases. You should use Q1.h as a header file and Q1main.cpp as a main function...

  • implement a C++ class name Vector. The Vector class contains a private double array of length...

    implement a C++ class name Vector. The Vector class contains a private double array of length 2 named elements that represents a two-dimensional vector. We will also implement an overloaded multiplication operator (*) that accepts a single Vector variable by reference and returns the Dot Product between the current Vector object and the one pointed to by the function argument in form of a double. Please recall that the dot product of two vectors a =(21,92) and 5 = (b1,b2)...

  •       C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for...

          C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for this part Add on to the lab12a solution(THIS IS PROVIDED BELOW). You will add an overload operator function to the operator << and a sort function (in functions.h and functions.cpp)    Print out the customer’s name, address, account number and balance using whatever formatting you would like    Sort on account balance (hint: you can overload the < operator and use sort from the...

  • C++ code please asap QUESTIONS Write the test main function as described next. This function is...

    C++ code please asap QUESTIONS Write the test main function as described next. This function is NOT a member function of either of the two classes above. It is located in separate source file. Create an array of type Flight and size 10 1. Prompt the user to enter values for speed, name, and id for all 10 objects. You must use the overloaded input stream operator of class Flight. 1. Write the value of the name variable of all...

  • You are to write a basic fitness application, in C++, that allows the user of the...

    You are to write a basic fitness application, in C++, that allows the user of the application to manually edit “diet” and “exercise” plans. For this application you will need to create three classes: DietPlan, ExercisePlan, and FitnessAppWrapper. Diet Plan Attributes: The class DietPlan is used to represent a daily diet plan. Your class must include three data members to represent your goal calories (an integer), plan name (a std::string), and date for which the plan is intended (a std::string)....

  • Thank you for your help! Homework 02 - Vectors, Strings, and Masking Function Name: badWeatherman Inputs: 1. (logical)...

    Thank you for your help! Homework 02 - Vectors, Strings, and Masking Function Name: badWeatherman Inputs: 1. (logical) Vector of suspect #1's answers to a lie detector (logical) Vector of suspect #2's answers to a lie detector (logical) Vector of suspect #3's answers to a lie detector (logical) Vector of suspect #4's answers to a lie detector 2" 3. 4. Outputs 1. (char) Sentence stating which suspect stole the fruit Banned Functions: isequal (, isequaln( Background Oh no, there has...

  • C++: questions are in fish.h. Write the code in fish.cpp and main.cpp #ifndef FISH_H #define FISH_H...

    C++: questions are in fish.h. Write the code in fish.cpp and main.cpp #ifndef FISH_H #define FISH_H #include <vector> class Fish { public: // (1 point) // Write code to initialize edible to is_edible, age to 0, size to 1. Fish (bool is_edible); // (1 point) // Print the vital stats (size and age) of the fish. void Print(); // (1 point) // If fish is at least the age of reproduce_age, reproduce with probability // of reproduce_probability. If reproduce, return...

  • You are to write two functions, printString() and testString(), which are called from the main function....

    You are to write two functions, printString() and testString(), which are called from the main function. printString (string) prints characters to std::cout with a space after every character and a newline at the end. testString (string) returns true if the string contains two consecutive characters that are the same, false otherwise. See the main() to see how the two functions are called. Some sample runs are given below: string: “hello” printString prints: h e l l o testString returns: true...

  • Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...

    Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT