Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  fun
Language: C/C++
Code:
#include<iostream>
#include<string.h>
#include<unistd.h>
#include<stdio.h>
using namespace std;
void Create();
void Proceed();
void Quad();
string u1,p1,un,pn,u2="pkatti",u3="pvamsi",u4="nnaveen",u5="snayaki",p2="pandu",p3="vamsi",p4="naveen",p5="nayaki";
int main()
{
     string u,p;
     int x;
     cout<<"\n1.Login 2.Signup 3.Guest 4.Exit\n";
     cin>>x;
     if(!cin)
     {
        exit(0);
     }
     else
     {
          switch(x)
          {
               case 1 : Proceed(); break;
               case 2 : Create(); break;
               case 3 : Quad(); cout<<"\nTo enter roots multiple times please login with your credentials or create account...\n\n"; sleep(25); main(); break;
               case 4 : cout<<"EXITING..."; sleep(5); exit(0); break;
               default : cout<<"\nEnter proper choice !!"; main();
          }
     }
    return 0;
}
void Quad()
{
    int a,b,s,p;
    cout<<"\nEnter the roots : \n";
    cin>>a>>b;
    if(!cin)
    {
        cout<<"\nEnter proper inputs.\nTerminating Program...\n";
        sleep(5);
        exit(0);
    }
    s=a+b;
    p=a*b;
    if(a>0)
    {
        if(b>0&&a!=b)
        {
            cout<<"\nThe equation is : x^2-"<<s<<"x+"<<p<<"=0";
        }
         if(a==b)
        {
             cout<<"\nThe equation is : (x-"<<a<<")^2=0";
         }
    }
    if((a>0&&b<0)||(a<0&&b>0))
    {
        if(a>b)
        {
            if(a==-b)
         {
          cout<<"\nThe equation is : x^2"<<p<<"=0";
         }
         else if((a+b>0))
         {
          cout<<"\nThe equation is : x^2+"<<s;
              cout<<"x"<<p<<"=0";
         }
         else if((a+b<0))
         {
          cout<<"\nThe equation is : x^2"<<s;
              cout<<"x"<<p<<"=0";
         }
         else if(b<0)
         {
              cout<<"\nThe equation is : x^2+"<<s;
              cout<<"x"<<p<<"=0";
         }
        }
     else if(a==-b)
     {
         cout<<"\nThe equation is : x^2"<<p<<"=0";
     }
     else if(a<b)
     {
         if(a==-b)
              cout<<"\nThe equation is : x^2"<<p<<"=0";
         else if((a+b>0))
         {
          cout<<"\nThe equation is : x^2+"<<s;
              cout<<"x"<<p<<"=0";
         }
         else if((a+b<0))
         {
          cout<<"\nThe equation is : x^2"<<s;
              cout<<"x"<<p<<"=0";
         }
     }
        else
     {
            cout<<"\nThe equation is : x^2"<<s;
         cout<<"x"<<p<<"=0";
     }
    }
    if(a<0)
    {
        if(b<0&&a!=b)
        {
            cout<<"\nThe equation is : x^2+"<<-s;
         cout<<"x+"<<p<<"=0";
        }
         if(a==b)
         {
         cout<<"\nThe equation is : (x+"<<-a<<")^2=0";
         }
    }
    if(a==0)
    {
     if(b==0)
     {
          cout<<"\nNot a quadratic equation\n";
     }
    }
    if(a==0&&b!=0&&b>0)
     cout<<"\nThe equation is : x^2-"<<b<<"x=0";
    if(b==0&&a!=0&&a>0)
     cout<<"\nThe equation is : x^2-"<<a<<"x=0";
     if(a==0&&b!=0&&b<0)
     cout<<"\nThe equation is : x^2+"<<-b<<"x=0";
    if(b==0&&a!=0&&a<0)
     cout<<"\nThe equation is : x^2+"<<-a<<"x=0";
}
void Proceed()
{
    string u,p;
    int i=0;
     state :
         cout<<"\nUSERNAME : ";
         cin>>u;
         cout<<"\nPASSWORD : ";
         cin>>p;
         if((u==u2&&p==p2)||(u==u3&&p==p3)||(u==u4&&p==p4)||(u==u5&&p==p5)||(u==u1&&p==p1))
         {
              while(true)
             {
                      int v;
                      cout<<"\n\n1.Insert roots and display equation    2.Logout   3.Exit\n";
                      cin>>v;
               if(!cin)
                    exit(0);
                      switch(v)
                      {
                               case 1 : Quad(); break;
                               case 2 : main(); break;
                               case 3: cout<<"EXITING..."; sleep(5); exit(0);
                               default : cout<<"\nEnter proper choice !!\n";
                      }
                 }
         }
         else
     {
              cout<<"\nInvalid USERNAME OR PASSWORD\n";
          while(i<2)
          {
              int h;
            cout<<"\n1.Forgot Credentials ? 2.Continue \n";
            cin>>h;
            if(cin)
            {
                switch(h)
                {
                    case 1: Create(); break;
                    case 2: goto s4;
                    default: exit(0);
                }
            }
            else
                exit(0);
            s4:
                i++;
                goto state;
          }
          cout<<"\nYou've Entered Incorrect Credentials Multiple times\n";
          cout<<"\nEXITING....";
          sleep(6);
          exit(0);
     }
}
void Create()
{
     string u,p;
     cout<<"\nDE_USERNAME : ";
     cin>>u;
     cout<<"\nDE_PASSWORD : ";
     cin>>p;
     if(u=="system"&&p=="roots")
     {
          cout<<"\nCreate USERNAME : ";
          cin>>u1;
          cout<<"\nCreate PASSWORD : ";
          cin>>p1;
             if(u1==u2||u1==u3||u1==u4||u1==u5||u1==un)
             {
                      cout<<"\nUser already exists!";
                      main();
             }
              else
              {
                  cout<<"\nUSER CREATED SUCCESSFULLY..\n";
                  un=u1;
                  main();
              }
     }
     else
     {
          cout<<"\nNever forget your Desktop USERNAME & PASSWORD\n";
          cout<<"\nOpening in GUEST MODE...";
          sleep(8);
        Quad();
        cout<<"\nTo enter roots multiple times please login with your credentials or create account...\n\n";
        sleep(25);
        main();
     }
}

Comments: