Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include <iostream>
#include <iomanip>
using namespace std;

void codeform();

int main()
{
    codeform();
    int Size;
    codeform();
    // enter size of vector
    cout<<"________________________________________________________________"<<endl;
    cout<<"enter size of vector(the vector is equal to other v2,v3)"<<endl;
    cin>>Size;
    double arr[Size],Arr[Size],A[Size];
    //enter vectores
    cout<<"__________________________________"<<endl;
    cout<<"enter values of vector 1:"<<endl;
    for(int i="0;i<Size;i++)
    {
         cin>>arr[i];
    }
    cout<<"__________________________________"<<endl;
    cout<<"enter values of vector 2:"<<endl;
    for(int i="0;i<Size;i++)
    {
         cin>>Arr[i];
    }
    cout<<"__________________________________"<<endl;
    cout<<"enter values of vector 3:"<<endl;
    for(int i="0;i<Size;i++)
    {
         cin>>A[i];
    }
    // display vectors
    cout<<"__________________________________"<<endl;
    cout<<"your entered vector 1 is: "<<endl;
    for(int i="0;i<Size;i++)
    {
         cout<<arr[i];
         cout<<endl;
    }
    cout<<"__________________________________"<<endl;
    cout<<a[i];
    char choise;
    int value;
    cout<<"is all correct or you want to edit: please answer y(yes) n(no)"<<endl;
    cin>>choise;
    // check entered vector
    while(choise=='N')
    {
        cout<<"what vector do you want to edit"<<endl;
        cin>>value;
        if(value>3 || value<1)
        {
            cout<<"invalid enterd value"<<endl;
        }
        switch(value)
        {
        case(1):
            cout<<"_________________________________________"<<endl;
            cout<<"enter the new vector"<<endl;
            for(int i=0;i<Size;i++)
            {
                cin>>arr[i];
            }
            break;
        case(2):
            {
                cout<<"_________________________________________"<<endl;
                cout<<"enter the new vector"<<endl;
                for(int i=0;i<Size;i++)
                {
                    cin>>Arr[i];
                }
                break;
            }
        case(3):
            {
                cout<<"_________________________________________"<<endl;
                cout<<"enter the new vector"<<endl;
                for(int i=0;i<Size;i++)
                {
                     cin>>A[i];
                }
                break;
            }
        }
        cout<<"Is all vector correct or you want to edit: "<<endl;
        cout<<"please answer y(yes) or n(no)"<<endl;
        cin>>choise;
        if (choise=='Y')
        {
            break;
        }
    }

    // assume Y1=X1
    double sum=0,temp=0;
    double M[Size],N[Size],S[Size];
    for(int i=0;i<size;i++)
    {
        m[i]=arr[i];
    }
    //calculate y2=2+alphaY1
    for(int i=0;i<Size;i++)
    {
        sum+=M[i]*Arr[i];
    }
    for( int j=0;j<Size;j++)
    {
       {
           temp+=M[j]*M[j];
       }
    }
    double alpha;
    if( sum>0 )
    {
        alpha=(-1)*(sum/temp);
    }
    else
    {
        alpha=(sum/temp);
    }
    // calculate y3=x3+gammay2+betay1
    for(int i=0;i<size;i++)
    {
        n[i]=Arr[i]+(alpha*M[i]);
    }
    double store=0;
    for(int i=0;i<Size;i++)
    {
        store+=M[i]*A[i];
    }
    double beta;
    if(store>0)
    {
        Beta=(-1)*(store/temp);
    }
    else
    {
        Beta=(store/temp);
    }
    double pocket=0;
    for(int i=0;i<size;i++)
    {
        pocket += N[i]*A[i];
    }
    double box=0;
    for(int i=0;i<Size;i++)
    {
        box+=N[i]*N[i];
    }
    double gamma;
    if(gamma>0)
    {
        gamma=(-1)*(pocket/Box);
    }
    else
    {
        gamma=pocket/Box;
    }
    for(int i=0;i<size;i++)
    {
        s[i]=A[i]+(gamma*N[i])+(Beta*M[i]);
    }
    // check for orthogonal
    int orth=0;
    for(int i=0;i<Size;i++)
    {
        orth+=M[i]*N[i];
    }
    int orthong=0;
    for(int orthong+=M[i]*S[i];
    }
    int orthongonal=0;
    for(int orthongonal+=N[i]*S[i];
    }
    // display values y1,y2,y3
    cout<<"y1="<<endl;
    for(int i=0;i<Size;i++)
    {
        cout<<M[i]<<endl;
    }
    cout<<" ______________________________________________"<<endl;
    cout<<"y2="<<endl;
    for(int i=0;i<Size;i++)
    {
        cout<<N[i]<<fixed<<setprecision(4)<<endl;
    }
    cout<<" ______________________________________________"<<endl;
    cout<<"y3="<<endl;
    for(int i=0;i<Size;i++)
    {
        cout<<S[i]<<fixed<<setprecision(4)<<endl;
    }
    cout<<" ______________________________________________________"<<endl;
    cout<<"check orthongonality by inner product"<<endl;
    if(orth==0&&Orthong==0&&Orthongonal==0)
    {
        cout<<"<y1,y2>= "<<orth<<endl;
        cout<<"<y2,y3>= "<<orthong<<endl;;
        cout<<"<y1,y2>= "<<orthongonal<<endl;;
    }
    return 0;
}

void codeform()
{
    cout<<"manual solution:"<<endl;
    cout<<"assume y1=X1"<<endl;
    cout<<"  y2=x2+alphaY1"<<endl;
    cout<<"  y3=X3+betaY2+gammaY1"<<endl;
    cout<<"we need to find alpha,beta,gamma"<<endl;
}


What I have tried:

i tried alot but i cannot do anything
Posted
Updated 20-Dec-21 6:49am
v3
Comments
CHill60 20-Dec-21 4:50am    
If you cannot do anything what do you expect us to do?
You already have a User Interface - You are outputting to the console and inputting data from the user. Be specific

We can't do that for you: we have no idea what you expect the application to do, much less what you expect it to "look and feel" like to the user.

A "user interface" is just that: a lay of application that communicates to the user and gets the user choices back. That can be anything: from text based with strings being printed to the user and him typing when allowed as you have there, right through a "full GUI" like a Windows or mobile phone app, to a browser based website, a 3d viewer based app, or even a game-style interface with custom controllers.

You need to sit down, work out exactly what you want to produce, and mock it up (on computer or paper) and then work out the environment it will work in, and how exactly every component interacts with the user.
Then you can start designing code for a "user interface".

But we can't do any of that for you!
 
Share this answer
 
If your are free in the choice of the UI than you should take a look at Qt because it has some multiplatform features. Here ist the Getting Started with Qt where you can inform how to use it. Or watcht some tutorial videos.
Another option is to the MS Visual Studio but than you are a bit tied to the Windows platform.
 
Share this answer
 
I tried to edit your post to get rid of the extraneous spaces but there were a few lines lost in translation.

Your code is actually very basic but it is difficult to see the forest through the trees because it is so cluttered. Much of that is due to repeated sequences of code. These should be made into functions. I will show you a couple of examples.
C++
void InputArray( const char * text, double array[], int size )
{
    cout<<"_________________________________________" << endl;
    cout<<"enter the new vector " << text << " : " << endl;
    for(int i=0;i<size;i++)
    {
        cin>>array[i];
    }
}


void OutputArray( const char * text, const double array[], int size )
{
    cout<< text <<endl;
    for(int i=0;i<size;i++)
    {
        cout << array[ i ] <<fixed << setprecision(4) << endl;
    }
    cout<<" ______________________________________________"<<endl;
}
then you can use these two function any time you want to input or output and array and I see that you do that many times in your code. Now your code can look like this :
C++
 // enter vectors
InputArray( "enter values of vector 1:", arr, Size );
InputArray( "enter values of vector 2:", Arr, Size );
InputArray( "enter values of vector 3:", A, Size );
// display vectors
OutputArray( "vector 1 values : ", arr, Size );
OutputArray( "vector 2 values : ", Arr, Size );
OutputArray( "vector 3 values : ", A, Size );
these functions can be used later in your code also :
C++
    // display values y1,y2,y3
OutputArray( "y1=", M, Size );
OutputArray( "y2=", N, Size );
OutputArray( "y3=", S, Size );
This will clean up your code considerably and let you see the computational logic more clearly.

One other tip : consider putting all of your input values into a file and then reading the data from it. You don't have to do much at all to your logic. The key is in how you run the program. If you have your input in a file called, 'InputData.txt" then to run your program you can type this at a command prompt : "YourProgram < InputData.txt" and it will read the data file just as if you had entered the data by hand. This will speed up your debugging process A LOT!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900