lundi 22 juillet 2019

non-member about header privates

Figuras.h

 #ifndef FIGURAS_H
    #define FIGURAS_H

    #include <vector>
    #include <iostream>
    #include <string>

    using namespace std;

    typedef vector<pair<double,double>> vec;
    typedef pair<double,double> punto;


    class Figuras{

    private:
        string tipo;
        vec Coord;
        punto inicio = {0.0,0.0};

    public:

        void crea_figura();
        void trasladar(punto P);
        void mostrar_fig();
    };
    #endif;

Figuras.cpp

#include "Figuras.h"

using namespace std;

    void crea_figura(){
        int x;
        string c;

        cout << "cuants punts?" << endl;
        cin >> x;
        if(x==2){
            cout<<"Ci para circulo, Se para segmento"<<endl;
            cin>>c;
            if(c=="Ci") {tipo = "Ci";}
            else{tipo = "Se";}
        }
        if(x==3) tipo = "Tr";
        if(x==4){
            cout<<"Cu para cuadrado, Re para rectangulo"<<endl;
            cin>>c;
            if(c=="Cu") {tipo = "Cu";}
            else{tipo = "Re";}
        }
        Coord(x); // Declare vector of pairs as long as user wants
        Punto P;
        for (int i = 0; i < V.size(); i++) { //fill vector with coords
            cout << "Introdueix coordenada numero: " << i<<"format (double,double)";
            cout << "x: ";
            cin >> P.first;
            cout << "y: ";
            cin >> P.second;
            Coord[i] = P;
        }

        /*for (int c = 0; c < V.size(); c++) { //show all coords
            P.first = Coord[c].first;
            P.second = Coord[c].second;
            cout <<"("<< P.first<< "," << P.second<<")" << endl;
        }*/
    }
    void trasladar(punto P){
        double difx,dify;
        difx=P.first - inicio.first;
        dify=P.second - inicio.second;
        if (Coord != NULL){
            for(int i=0; i<Coord.size(); i++){
                Coord[i].first += difx;
                Coord[i].second += dify;
            }
        }
        else {crea_figura();trasladar(P);}
    }
    void mostrar_fig(){
        for (int c = 0; c < V.size(); c++) { //show all coords
            cout <<c<<" :("<< Coord[c].first<< "," << Coord[c].second << ")" << endl;
        }
    }

main.cpp

#include <iostream>
#include <string>
#include <vector>
#include "Figuras.cpp"
using namespace std;


int main(){
    Figuras fig;
    fig.crea_figura();


    }

Terminal Errors:

In file included from main.cpp:4:0: Figuras.cpp: In function ‘void crea_figura()’: Figuras.cpp:14:20: error: ‘tipo’ was not declared in this scope if(c=="Ci") {tipo = "Ci";} ^~~~ Figuras.cpp:15:12: error: ‘tipo’ was not declared in this scope else{tipo = "Se";} ^~~~ Figuras.cpp:17:15: error: ‘tipo’ was not declared in this scope if(x==3) tipo = "Tr"; ^~~~ Figuras.cpp:21:20: error: ‘tipo’ was not declared in this scope if(c=="Cu") {tipo = "Cu";} ^~~~ Figuras.cpp:22:12: error: ‘tipo’ was not declared in this scope else{tipo = "Re";} ^~~~ Figuras.cpp:24:13: error: ‘Coord’ was not declared in this scope Coord(x); // Declare vector of pairs as long as user wants ^ Figuras.cpp:25:6: error: ‘Punto’ was not declared in this scope Punto P; ^~~~~ Figuras.cpp:26:26: error: ‘V’ was not declared in this scope for (int i = 0; i < V.size(); i++) { //fill vector with coords ^ Figuras.cpp:29:17: error: ‘P’ was not declared in this scope cin >> P.first; ^ Figuras.cpp: In function ‘void trasladar(punto)’: Figuras.cpp:43:18: error: ‘inicio’ was not declared in this scope
difx=P.first - inicio.first; ^~~~~~ Figuras.cpp:45:7: error: ‘Coord’ was not declared in this scope if (Coord != NULL){ ^~~~~ Figuras.cpp: In function ‘void mostrar_fig()’: Figuras.cpp:54:23: error: ‘V’ was not declared in this scope for (int c = 0; c < V.size(); c++) { //show all coords ^ Figuras.cpp:55:28: error: ‘Coord’ was not declared in this scope cout <

so guys any way to solve this problems?? i do really have to practice more hahahhaha those mistakes are for non-practice hope it'll be helpful for some other people.

Aucun commentaire:

Enregistrer un commentaire