Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I can't find an error

0 votes
asked Jun 4, 2020 by Гачибасер 228 (130 points)
You need to print the point A with coordinates x;y.(the first lines of the code are the solution to another task) I can't find the error, the program is looking for x, y incorrectly

#include <iostream>

using namespace std;

int main()
{
    int N, k;
        cout<<"Введите кол-во точек: ";
        cin>>N;
        int ch[9][N+1];
        for(int i=0 ; i<4; i++){
            for(int j=0; j<=N; j++){
            ch[i][j]=0;}
        }
        int x[N], y[N];
        for(int i=0; i<N; i++){
            cout<<"Введите абсциссу: ";
            cin>>x[i];
            cout<<"Введите ординату: ";
            cin>>y[i];
            if(x[i] > 0 && y[i] > 0){
                ch[1][0]++;
                ch[1][ch[1][0]]=i;
            }
            else if(x[i] > 0 && y[i] < 0){
                ch[4][0]++;
                ch[4][ch[4][0]]=i;
               
            }
            else if(x[i] < 0 && y[i] > 0){
                ch[2][0]++;
                ch[2][ch[2][0]]=i;
            }
            else if(x[i] < 0 && y[i] < 0){
                ch[3][0]++;
                ch[3][ch[3][0]]=i;
            }
            else{
                ch[0][0]++;
            }
        }
        int max=0;
        for(int i=1; i<4; i++){
            for(int j=i+1; j<=4; j++){
                if(ch[i][0]>ch[j][0] && ch[i][0]>max){
                    k=i;
                    max=ch[i][0];
                }else if(ch[i][0]<ch[j][0] && ch[i][0]>max){
                    k=j;
                    max=ch[j][0];
                }
            }
        }
       cout<<"k="<<k<<endl;
       cout<<"m="<<max<<endl;
       int min=1000;
       int A=0;
       int Ax=0;
       int Ay=0;
       int minx=1000;
       int miny=1000;
        for(int i=1; i<=max; i++){
            if(abs(x[ch[k][i]])<minx){
                Ax=i;
                minx=abs(x[ch[k][i]]);
            }if(abs(y[ch[k][i]])<miny){
                Ay=i;
                miny=abs(y[ch[k][i]]);}
        }
        if(minx<miny){
            A=Ax;
            min=minx;
        }else{
            A=Ay;
            min=miny;
        }
        for(int i=0; i<max; i++){
            if(abs(x[ch[i][Ax]])==(abs(x[ch[k][i]]))){
                    A=Ax;
                }if(abs(y[ch[i][Ay]])==(abs(y[ch[k][i]]))){
                    A=Ay;
                }
        }
        cout<<"A="<<A<<endl;
        cout<<"R="<<min<<endl;
     return 0;
}

1 Answer

+2 votes
answered Jun 6, 2020 by xDELLx (10,500 points)
//Points to keep in mind when you want HELP

//Explain what the current prog does, this didnt have syntax errors & had prob in logic

//Put as many comments as possible

//My attempt to help u below

#include <iostream>

using namespace std;

int main()
{
    int N, k;
        cout<<"Введите кол-во точек: /Enter the No. of Co-ordinates ?? :";
        cin>>N;
        N=10;
        int ch[9][N+1];
        for(int i=0 ; i<9; i++){    //when we have the 9 rows in ch ,why init only 4,
                                    //it cuases garbage values to be read when checking quadrants
            for(int j=0; j<=N; j++){
            ch[i][j]=0;}
        }
        //int x[N], y[N];
        //debug
        int x[N]={1,3,-1,-3,-5,2,4,-6,-7,0};
        int y[N]={2,4,-2,-4,-6,-3,-5,7,8,0};
        //debug
        for(int i=0; i<N; i++){
            cout<<"Введите абсциссу:(Enter x point /axis??) "<< x[i];
          //  cin>>x[i];
             // cout <<x[i];
            cout<<"Введите ординату:(Enter y point /axis??) "<< y[i] ;
            //cin>>y[i];
            //cout<<y[i];
            //ch[i][0] always holds count of # of co-ordinates
            //present in the current quadrant {i in [1,2,3,4] }
            //check if x,y is part of 1,2,3,4 quadrant
            //increment count of co-ord in that quadrant & place it in nn-occupied posisiton
            if(x[i] > 0 && y[i] > 0){
                int c = ch[1][0];
                c++;
                ch[1][0]=c;
                ch[1][c]=i;
            }
            else if(x[i] > 0 && y[i] < 0){
                int c = ch[4][0];
                c++;
                ch[4][0]=c;
                ch[4][c]=i;
               
            }
            else if(x[i] < 0 && y[i] > 0){
                int c = ch[2][0];
                c++;
                ch[2][0]=c;
                ch[2][c]=i;
            }
            else if(x[i] < 0 && y[i] < 0){
                int c = ch[3][0];
                c++;
                ch[3][0]=c;
                ch[3][c]=i;
            }
            else{
                int c = ch[0][0];
                c++;
                ch[0][0]=c;
                
            }
        }
       /*
        int max=0;
        for(int i=1; i<4; i++){
            for(int j=i+1; j<=4; j++){
                if(ch[i][0]>ch[j][0] && ch[i][0]>max){
                    k=i;
                    max=ch[i][0];
                }else if(ch[i][0]<ch[j][0] && ch[i][0]>max){
                    k=j;
                    max=ch[j][0];
                }
            }
        }
        */
        //Find the quadrant(k) with maximum co-ordinates(max)
        int max=0;
        for (int i=1;i<=4;++i){
            if (max < ch[i][0])
            {
                k=i;
                max=ch[i][0];
            }
        }    
       cout<<"quadrant with maximum co-ordinates present, k="<<k<<endl;
       cout<<"Count of co-ordinates present, m="<<max<<endl;
       int min=1000;
       int A=0;
       int Ax=0;
       int Ay=0;
       int minx=1000;
       int miny=1000;
        for(int i=1; i<=max; i++){
            //Find point closet to 0,0 in quadrant having maximum co-ordinates ??
            if(abs(x[ch[k][i]])<minx){
                Ax=i;
                minx=abs(x[ch[k][i]]);
            }if(abs(y[ch[k][i]])<miny){
                Ay=i;
                miny=abs(y[ch[k][i]]);}
        }
        if(minx<miny){
            A=Ax;
            min=minx;
        }else{
            A=Ay;
            min=miny;
        }
        //By now I dont have patience to understand what below loop is for :( )
        for(int i=0; i<max; i++){
            if(abs(x[ch[i][Ax]])==(abs(x[ch[k][i]]))){
                    A=Ax;
                }if(abs(y[ch[i][Ay]])==(abs(y[ch[k][i]]))){
                    A=Ay;
                }
        }
        cout<<"A="<<A<<endl;
        cout<<"R="<<min<<endl;
     return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...