Please let me know if you have any doubts or you want me to modify
the answer. And if you find this answer useful then don't forget to
rate my answer as thumps up. Thank you! :)
//main.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include "VectorRecursion.h"
int main(){
std::vector<int> vecInt;
std::ifstream
fin("/Users/swapnil/CLionProjects/VectorRecursion/RandomData.txt");
while(fin){
int fin_in;
fin >>
fin_in;
if (!fin)
break;
vecInt.push_back( fin_in
);
}
for (size_t i=0; i<vecInt.size();
++i){
std::cout <<
vecInt[i] << " same as " << vecInt.at(i) <<
std::endl;
}
for (std::vector<int>::iterator
it=vecInt.begin(); it!=vecInt.end(); ++it){
std::cout << *it
<< std::endl;
}
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//VectorRecursion.h
#ifndef VECTORRECURSION_VECTORRECURSION_H
#define VECTORRECURSION_VECTORRECURSION_H
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
void swap(vector<T> &v, T m, T n) {
T temp = v[m];
v[m] = v[n];
v[n] = temp;
}
template <typename T>
T divide(vector<T> &v, T l, T h) {
T p = v[h];
T r = l - 1;
T s = l;
while(s <= h - 1) {
if(v[s] <= p) {
++r;
swap(v, r, s);
}
++s;
}
swap(v, r + 1, h);
return (r + 1);
}
template <typename T>
void vector_resort(vector<T> &v, T l, T h) {
if(l < h) {
T p = divide(v, l,
h);
vector_resort(v, l, p -
1);
vector_resort(v, p + 1,
h);
}
}
template <typename T>
T vector_research(vector<T> &v, T l, T h, const T theory)
{
if(l > h) {
return -1;
}
T m = (l + h) / 2;
if(v[m] == theory) {
return m;
}
if(v[m] > theory) {
return
vector_research(v, l, m - 1, theory);
}
return vector_research(v, m + 1, h,
theory);
}
#endif //VECTORRECURSION_VECTORRECURSION_H
I need help writing this code in C++ Proj11.cpp is provided as well as the randomdata.txt thank you in advance! Objectives: The main objectives of this project is to introduce you to recursion,...
may i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #include<iostream> #include<string> #include<sstream> #include<stack> using namespace std; int main() { string inputStr; stack <int> numberStack; cout<<"Enter your expression::"; getline(cin,inputStr); int len=inputStr.length(); stringstream inputStream(inputStr); string word; int val,num1,num2; while (inputStream >> word) { //cout << word << endl; if(word[0] != '+'&& word[0] != '-' && word[0] != '*') { val=stoi(word); numberStack.push(val); // cout<<"Val:"<<val<<endl; } else if(word[0]=='+') { num1=numberStack.top(); numberStack.pop(); num2=numberStack.top(); numberStack.pop();...
Can someone please help me with this code? I'm writing in C++. Thank you in advance. Complete a program that represents a Magic Eight Ball (a Magic Eight Ball allows you to ask questions and receive one of several random answers). In order to complete this, you will need a couple of new functions. First, in order to get a line of input that can contain spaces, you cannot use cin, but instead will use getline: string question; cout <<...
Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...
In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits> #include <iostream> #include <string> // atoi #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ const unsigned int DEFAULT_SIZE = 179; // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() {...
C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...
C++. Need some help getting started. We will also have the following two functions: 1. A mutate function that randomly modifies a chromosome. 2. A crossover function that takes two chromosomes and splits each one at the same spot, then combines them together. Our genetic algorithm works by iterating over generations of chromosomes via the following process: 1. Generate random population. 2. Until we get an answer that is good enough, do the next steps in a loop: (a) Do...
Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. The definition of the class for a binary tree (as a template) is given as follows: template < class T > class binTree { public: binTree ( ); // default constructor unsigned height ( ) const; // returns height of tree virtual void insert ( const T& ); //...
//Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; class googlePlayApp { private: string name; double rating; int numInstalls; int numReviews; double price; public: googlePlayApp(string, double, int, int, double); ~ googlePlayApp(); googlePlayApp(); string getName(); double getRating(); int getNumInstalls(); int getNumReviews(); string getPrice(); void setName(string); void setRating(double); void setNumInstalls(int); void setNumReviews(int); void setPrice(double); }; googlePlayApp::googlePlayApp(string n, double r, int ni, int nr, double pr)...
Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <stdio.h> #include <ctype.h> #include <string.h> #include <algorithm> using namespace std; /** This structure is to store the date and it has three integer fields **/ struct Date{ int day; int month; int year; }; /** This structure is to store the size of the box and it...