in this program i'm required to make a menu in the console, the user puts two arrays and it shows them some options to do with them, like finding their union and intersection, but until the user specifies to go out of here this menu has to work with those two arrays.
So i make the user input how big and which things go in each array, and each time the options are shown i print the arrays too, not a problem over there.
When the user picks a choice in the menu, it calls a void() function inside the main.cpp, and that void function calls a function over the aux cpp,
void conjuntos(){
cout<< "----------------------------------------"<<endl;
cout<< " Conjuntos "<<endl;
cout<< "----------------------------------------"<<endl;
char** opciones = new char*[6];
opciones[0] = "Union";
opciones[1] = "Interseccion";
opciones[2] = "Diferencia";
opciones[3] = "Diferencia simetrica";
opciones[4] = "Pertenece";
opciones[5] = "Contenido";
int opc;
//Here the user inputs each array
cout<<"Ingrese dos arreglos"<<endl;
cout<<"Arreglo 1 (cantidad): ";
int cant1;
cin>>cant1;
int arr1[cant1];
for(int i= 0;i<cant1;i++){
cout<<i+1<<". ";
cin>>arr1[i];
};
cout<<"Arreglo 2 (cantidad): ";
int cant2;
cin>>cant2;
int arr2[cant2];
for(int i= 0;i<cant2;i++){
cout<<i+1<<". ";
cin>>arr2[i];
};
do{
cout<< "----------------------------------------"<<endl;
cout<< " Conjuntos "<<endl;
cout<< "----------------------------------------"<<endl;
//Here the pc outputs the arrays
cout<<"Arreglo 1: [";
for(int i= 0;i<cant1;i++){
if( i==cant1-1){
cout<<arr1[i];
}else{
cout<<arr1[i]<<",";
};
};
cout<<"]"<<endl;
cout<<"Arreglo 2: [";
for(int i= 0;i<cant2;i++){
if( i==cant2-1){
cout<<arr2[i];
}else{
cout<<arr2[i]<<",";
};
};
cout<<"]"<<endl;
// !!!!!
cout<< "----------------------------------------"<<endl;
opc = menu(opciones, 6);
switch( opc ){
case 1: unido(); break;
case 2: interconjunto(); break;
case 3: diferencia(); break;
case 4: simetrica();break;
case 5: pertenece();break;
case 6: contenido();break;
};
}while(opc!=0);
cout <<" ------------------------------------------"<<endl;
cout <<" MENU PRINCIPAL "<<endl;
cout <<" ------------------------------------------"<<endl;
};
When the user picks a choice in the menu, it calls a void() function inside the main.cpp
void unido(){
cout<< "----------------------------------------"<<endl;
cout<< "El arreglo union de ambos conjuntos es: "<<endl;
cout<< unido(arr1,cant1,arr2,cant2);
};
And that void function calls a function over the aux cpp, with help of the .h
#ifndef CONJUNTOS_H_INCLUDED
#define CONJUNTOS_H_INCLUDED
int* unido(int* arr1,int cant1,int* arr2, int cant2);
#endif // CONJUNTOS_H_INCLUDED
Heres the aux cpp
#include <iostream>
#include "Enteros.h"
#include "Reales.h"
#include "Char.h"
#include "Conjuntos.h"
using namespace std;
int* unido(int* arr1,int cant1,int*arr2,int cant2){
cout<<"cant1";
return 0;
};
My question is that in void conjuntos() where is the menu, i have the arrays, i need to use them with each function that is called by this menu, but when i use a function like in void unido() it says the arr1, cant1, arr2 and cant2 are not specified in the functions, how do i send those variables from the conjuntos ** menu over the **unido function?