Hello Uncles and Aunties!

This is a discussion on Hello Uncles and Aunties! within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> #include<string.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> void menu() // main menu { printf("A......Addition\n"); printf("S......Subtraction\n"); printf("D......Division\n"); printf("M......Multiplication\n"); printf("F......Factorial\n"); printf("P......Power\n"); printf("G......String Operation\n"); ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    72

    Hello Uncles and Aunties!

    Code:
    #include<iostream.h>
    #include<string.h>
    #include<conio.h>
    #include<stdio.h>
    #include<stdlib.h>
    
    void menu() // main menu
    {
    printf("A......Addition\n");
    printf("S......Subtraction\n");
    printf("D......Division\n");
    printf("M......Multiplication\n");
    printf("F......Factorial\n");
    printf("P......Power\n");
    printf("G......String Operation\n");
    printf("E......Exit\n");
    printf("\t\tEnter Your Choice Please");
    }
    
    
    void add() // function for addition
    {
    char ch;
    while(1)
     {
     int a,b;
     clrscr();
     cout<<"\t\t\t\tAddition\nEnter 1st number:";
     cin>>a;
     cout<<"\nEnter 2nd number:";
     cin>>b;
     cout<<"\n"<<a<<"+"<<b<<"="<<(a+b);
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
        break;
          }
       }
    
    }
    
    
    void sub() // function for subtraction
    {
    char ch;
    while(17)
     {
     int a,b;
     clrscr();
     cout<<"\t\t\t\tSubtraction\nEnter 1st number:";
     cin>>a;
     cout<<"\nEnter 2nd number:";
     cin>>b;
     cout<<"\n"<<a<<"-"<<b<<"="<<(a-b);
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
        break;
          }
       }
    
    }
    
     
    
    void Division() // function for division
    {
    char ch;
    while(1)
     {
     int a,b;
     clrscr();
     cout<<"\t\t\t\tDivision\nEnter 1st number:";
     cin>>a;
     cout<<"\nEnter 2nd non-zero number:";
     cin>>b;
     cout<<"\n"<<a<<"/"<<b<<"="<<(a/b);
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
        break;
          }
       }
    
    }
    
     
    
    void Multiplication() // function for multiplication
    {
    char ch;
    while(1)
     {
     int a,b;
     clrscr();
     cout<<"\t\t\t\tMultiplication\nEnter 1st number:";
     cin>>a;
     cout<<"\nEnter 2nd number:";
     cin>>b;
     cout<<"\n"<<a<<"*"<<b<<"="<<(a*b);
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
        break;
          }
       }
    }
    
    
    void Power() // function for power
    {
    char ch;
    while(1)
     {
     int a,b;
     clrscr();
     cout<<"\t\t\t\tPower\nEnter number:";
     cin>>a;
     cout<<"\nEnter its power:";
     cin>>b;
       for(int i=1;i<b;i++)
        a*=a;
    
     cout<<"\n"<<a<<"^"<<b<<"="<<a;
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
        break;
          }
       }
    }
    
    
    void Factorial() // function to calculate factorial
    {
    char ch;
    while(1)
     {
       int a,c;
       clrscr();
       cout<<"\t\t\t\tFactorial\nEnter a number:";
       cin>>a;
       c=a;
       for(int i=c-1;i>0;i--)
        a*=i;
       cout<<c<<"!="<<a;
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
          break;
          }
       }
    }
    
    
    void printstr() // strings operation menu
    {
    clrscr();
    cout<<"\nR.....Reverse";
    cout<<"\nC.....Concatenation";
    cout<<"\nX.....Copy";
    cout<<"\nL.....Length";
    cout<<"\nB.....Back";
    cout<<"\nEnter Your Choice";
    }
    
    //    STRING PORTION  START //
    
    
    void reverse() // string function for reverse
    {
    char ch;
    while(1)
     {
       clrscr();
       char str[100];
       cout<<"\nEnter a String:";
       scanf("%s",&str);
       printf("\nReverse is %s",strrev(str));
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
          break;
          }
       }
    }
    
    
    void concat() // string function for concat
    {
    char ch;
    while(1)
     {
       clrscr();
       char str[100],str1[100];
       cout<<"\nEnter 1st String:";
       scanf("%s",&str);
       cout<<"\nEnter 2nd String:";
       scanf("%s",&str1);
       cout<<str<<"+"<<str1<<"=";
       cout<<strncat(str,str1,strlen(str1));
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
          break;
          }
       }
    }
    
    
    void copy() // string function for copy
    {
    char ch;
    while(1)
     {
       clrscr();
       char str[100],str1[100];
       cout<<"\nEnter 1st String:";
       scanf("%s",&str);
       cout<<"\nEnter 2nd string";
       scanf("%s",&str1);
       clrscr();
       cout<<"1st String="<<str;
       cout<<"\n2nd String="<<str1;
       cout<<"\nString 1 copied to string 2.....";
       strcpy(str,str1);
       cout<<"\nString 1="<<str;
    
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
          break;
          }
       }
    }
    
    
    void length() // string function for determining length
    {
    char ch;
    while(1)
     {
       clrscr();
       char str[100];
       cout<<"\nEnter a String:";
       scanf("%s",&str);
       cout<<"\nLength of"<<str<<"is  "<<strlen(str);
       cout<<"\nDo you want to run again?(Y/N)";
       ch=getch();
       if(ch=='n' || ch=='N')
        {
          clrscr();
          break;
          }
       }
    }
    
    
    void Strings() // main string operations
    {
    cout<<"\t\t\t\tString Operations\n";
    char ch='Y',str[10];
    while(ch!='b' || ch!='B')
     {
       printstr();
       ch=getch();
       switch(ch)
        {
          case'R':
          case'r':
           reverse();
             break;
          case'C':
          case'c':
           concat();
             break;
         case'x':
          case'X':
           copy();
         case'l':
          case'L':
           length();
             break;
          case'b':
          case'B':
           break;
          default:
           clrscr();
          }
          if(ch=='b' || ch=='B')
           {
           clrscr();
           break;
             }
       }
    }
    
     
    void main() // The program's Main Function (will display as the program executes)
    {
    char ch1='Y';
    cout<<"\n\n\n\n\t\t\tWelcome\n\n\t\t\tMy Calculator\n\n\t\t\tVersion 1.0\n\n\t\tPress any key.......";
    getch();
    clrscr();
    
    while(ch1!='e' || ch1!='E')
     {
    
       
       menu(); // will call the function menu
       ch1=getch();
     switch(ch1)
        {
          case'A':
          case'a':
           add();
             break;
          case'S':
          case's':
           sub();
             break;
          case'D':
          case'd':
           Division();
             break;
          case'M':
          case'm':
           Multiplication();
             break;
          case'F':
          case'f':
           Factorial();
             break;        
          case'P':
          case'p':
           Power();
             break;
          case'G':
          case'g':
           Strings();
             break;
          case'E':
          case'e':
           exit(0);
          default:
           clrscr();
    
      }
    
     }
    
    }
    Hello ! I want this program to be given a GUI, a graphical representation of this calculator, how do I do that?

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    You would implement a graphical user interface using some framework. I'd recommend the portable wxWidgets, freely available at http://wxwidgets.org. If you use Win32, MFC, or .Net, you're tied to the Windows platform. People that use Linux and Macs will scorn you, and your name will be cursed among men. :-)

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    Roflrofl

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    Edit: I dont know how to do it, any guidelines? i have to just include a library or what

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    No, because there is no standard GUI library for C or C++.
    We have to rely on 3rd parties. There are many libraries out there, loads for C++, and some for C.
    Pick one, get familiar with it and start your GUI career. And be forewarned, writing a GUI is nothing like writing a console app.
    And don't use void main: http://cpwiki.sourceforge.net/Void_main

    Further, don't use scanf; use std::getline.
    Don't use char; use std::string.
    And try getting the basics down first before venturing into GUIs. They're hardly trivial.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    Uh, well you don't just make a program "Graphical." I too would suggest wxWidgets, not the easiest, but it makes nice windows and the tutorials on the site arn't bad.

    or you could try SDL, but then everthing has to be make of pixels you draw one way or another yourself. Plus the current iteration seems to hate Vista.

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Or, you could use nCurses, or Qt, or if you really wanted to bang your head against the wall, tap into Java's cross platform GUI using the JNI API from C.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  8. #8
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    Hey i used to love playing puTTy based MUDDs, that used nCurses! (God, the horrible punctuation!)

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21