Using ONLY the following header functions:
#include <iostream> #include <string> #include <cassert> #include <vector> using namespace std;
Create a C++ function that satisfies the condition using recursion, NO WHILE OR FOR LOOPS.
Pre-condition:
s.size() == t.size()
Post-condition:
Returns a vector where the first string is the first character of s followed by the first character of t, the second string is the second character of s followed by the second character of t, and so on.
For example, zip("abc", "xyz") returns {"ax", "by", "cz"}.
These are the function names:
vector zip(const string& s, const string& t); void zip_test();
The test function should automatically run when called from main as such:
int main() {
void zip_test();
return 0;
}
!!! No FOR or WHILE Loops Allowed, Not Even the Testing Function !!! Should be done using recursion
// do comment if any problem arises
// code]Using ONLY the following header functions:
#include <iostream>
#include <string>
#include <cassert>
#include <vector>
using namespace std;
// Pre - condition : s.size() == t.size()
// Post - condition : Returns a vector where the first string is the
// first character of s followed by the first character of t,
// the second string is the second character of s followed
// by the second character of t, and so on.
vector<string> zip(const string &s, const string &t)
{
static int i = 0;
if (i == s.size())
{
i = 0;
return (vector<string>){};
}
// create s[i]+t[i]
string temp = "";
temp = s[i];
temp += t[i];
i++;
// recursive call
vector<string> temp1 = zip(s, t);
// add temp to vector
vector<string> temp2;
temp2.push_back(temp);
// add temp1 to temp2 vector
temp2.insert(temp2.end(), temp1.begin(), temp1.end());
// return temp2
return temp2;
}
// For example, zip("abc", "xyz")
// returns{"ax", "by", "cz"}.
void zip_test()
{
// call zip for testing
vector<string> testing = zip("abc", "xyz");
vector<string> output = {"ax",
"by",
"cz"};
// testing output
if (testing == output)
cout << "Correct\n";
else
cout << "Incorrect";
}
int main()
{
zip_test();
return 0;
}
Output:

Using ONLY the following header functions: #include <iostream> #include <string> #include <cassert> #include <vector> using namespace...
Using ONLY the following header functions: #include "cmpt_error.h" #include <iostream> #include <string> #include <vector> #include <cassert> using namespace std; Create a C++ function that satisfies the condition using recursion, NO WHILE OR FOR LOOPS. Pre-condition: a.size() == b.size(), and a.size() > 0 Post-condition: Returns a vector equal to {min(a[0],b[0]), min(a[1],b[1]), min(a[2],b[2]), ..., min(a[n],b[n])}, where n == a.size(). For example, min_vec({3, 4, 1}, {2, 5, 2}) returns the new vector {2, 4, 1}. These are the function headers: vector<int> min_vec(const vector<int>&...
C++ Standard Deviation with arrays and vectors: #include <vector> #include <cmath> #include <iostream> using namespace std; void fillVector(vector <double> &); double average(const vector <double> &); int main() { return 0; } void fillVector(vector <double> &v) { double d; while (cin >> d) { v.push_back(d); } } double average(const vector <double> &v) { double sum = 0.; for (int i = 0; i < v.size(); i++) { sum += v.at(i); } return sum / v.size(); } standardDeviation() //stuck on this part...
Example program
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<int> factor(int n)
{
vector <int> v1;
// Print the number of 2s that divide n
while (n%2 == 0)
{
printf("%d ", 2);
n = n/2;
v1.push_back(2);
}
// n must be odd at this point. So we can
skip
// one element (Note i = i +2)
for (int i = 3; i <=...
#include <iostream>
#include <string>
using namespace std;
void get_user_string(string *);
string convert_to_dash(String* );
int_search_and_replace(char, string, string
&);
int main (){
string s;
cout << "Enter a string:" << endl;
get_user_string(&s);
string dash_version =
convert_to_dash(&s)
if ( dash_version != 32){
&s.push_back('-');
}
Here is an example operation of the completed program: Please enter a string: the weather is great! The dash-version of your string is: Please tell me the char that...
vector.h: #ifndef VECTOR_H #define VECTOR_H #include <algorithm> #include <iostream> #include <cassert> template <typename T> class Vector { public: Vector( int initsize = 0 ) : theSize( initsize ), theCapacity( initsize + SPARE_CAPACITY ) { objects = new T[ theCapacity ]; } Vector( const Vector & rhs ) : theSize( rhs.theSize), theCapacity( rhs.theCapacity ), objects( 0 ) { objects = new T[ theCapacity ]; for( int k = 0; k < theSize; ++k) objects[ k ] = rhs.objects[ k...
#include "stdafx.h" #include <iostream> #include <vector> #include <cassert> using namespace std; // function prototypes int loadDisk(vector<int> &firstPeg, int numDisks); void printPeg(vector<int> &peg); int hanoi(struct pegType &startPeg, struct pegType &swapPeg, struct pegType &endPeg, int numDisk); void moveDisk(struct pegType &startPeg, struct pegType &endPeg); struct pegType { vector <int> diskStack; int name; }; int main() { int numDisk = 7; int i; pegType peg1, peg2, peg3; peg1.name = 1; peg2.name = 2; peg3.name = 3;...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
Below is the given code of implementation:
#include <string>
#include <iostream>
#include <list>
#include <cassert>
using namespace std;
class List;
class Iterator;
class Node
{
public:
/*
Constructs a node with a given data value.
@param s the data to store in this node
*/
Node(string s);
/* Destructor */
~Node() {}
private:
string data;
Node* previous;
Node* next;
friend class List;
friend class Iterator;
};
class List
{
public:
/**
Constructs an empty list.
*/
List();
/* Destructor. Deletes...
Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass { public: void print() const; baseClass(string s = " ", int a = 0); //Postcondition: str = s; x = a; protected: int x; private: string str; }; class derivedClass: public baseClass { public: void print() const; derivedClass(string s = "", int a = 0, int b = 0); //Postcondition: str = s; x = a; y = b; private: int y; }; int...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...