Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are quite a few small errors. If Someone can Please rectify the errors in

ID: 3733496 • Letter: T

Question

There are quite a few small errors. If Someone can Please rectify the errors in c++ but first the Code below is All together, can we create a header file that defines and implements for the void combination function that is passed onto the main driver. The DisplayCombination stays in the driver. The main will run the function and get output and show results.

#include <iostream>
#include <vector>


// Function Prototype of the combination function
void combination(vector<int> itVect, int r, int n) ;

void displayCombination( vector<int> itVect, int r , int n){
  
  
combination (itVect,r, n); // Display combinations with temporary array
}


void combination(vector<int> itVect, int r, int n){
  
if (index == r){
for (int i = 0; i<r; i++){
std::cout << itVect[i] ;
}
std::cout << std:: endl ;
}
  
for (int i = 0; i < end && end - i + 1 >= r - index; i++ ){
  
itVect[r] = itVect[i] ;
combination (itVect, solVect, i+1, end, index + 1, r);
}
}

int main (){
  
std::vector<int> itVect = {1,2,3,4,5};
  
auto r = combination(itVect,3,5);
  
int n = (sizeof(itVect) / sizeof(itVect[0])) ;
  
displayCombination ( itVect, n, r );
}

Explanation / Answer

You can create a header file and include the header file in cpp file

/*******************/

/*
* Combination.h
*
* Created on: 20-Mar-2018
*      Author: tan
*/
#include <vector>

using namespace std;
#ifndef COMBINATION_H_
#define COMBINATION_H_

// Function Prototype of the combination function
int combination(vector<int> itVect, int r, int n) ;

// Function Prototype of the displayCombination function
void displayCombination( vector<int> itVect, int r , int n);

#endif /* COMBINATION_H_ */


/************************/ Combination.cpp

#include <iostream>
#include <vector>
#include "Combination.h"
using namespace std;


void displayCombination( vector<int> itVect, int r , int n){


combination (itVect,r, n); // Display combinations with temporary array
}


int combination(vector<int> itVect, int r, int n){

   if(r>=n)
       return r;
   for (int i = 0; i<r; i++){
   std::cout << itVect[i] ;
   }
   std::cout << std:: endl ;


   for (int i = 0; i < itVect.size(); i++ ){

   itVect[r] = itVect[i] ;
   return combination (itVect, i+1,r);
   }
}

int main (){

   vector<int> itVect{1,2,3,4,5};

   int r = combination(itVect,3,5);

int n = itVect.size();

displayCombination ( itVect, n, r );
}

/********************./

your implementation of combination() is incorrect. You are calling a recursive function without an exit point which will cause segmentation fault. See the provided corrected code

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote