Page 1 of 2 12 LastLast
Results 1 to 20 of 27

C++ Programs

This is a discussion on C++ Programs within the C++ forums, part of the Courses category; If you have a C++ program, add that here. Here is a program in C++, which will arrange Five user ...

  1. #1
    Senior Student Adnan Ahmad Khan's Avatar
    Join Date
    Aug 2010
    Location
    Bannu/Pakisatn
    Age
    27
    Posts
    261

    Thumb Down C++ Programs

    If you have a C++ program, add that here.

    Here is a program in C++, which will arrange Five user entered Numbers in Ascending order.

    #include<iostream.h>
    void arrange (int*,int*);
    main()
    {
    int num[5];
    cout<<"Enter Five Numbers :";
    for (int i=0; i<5; i++)
    {
    cin>>num[i];
    }
    cout<<endl;
    for (int c=0; c<5; c++)
    {
    for (int j=0; j<5; j++)
    {
    arrange (&num[j],&num[j+1]) ;
    }
    }
    for (int k=0; k<5; k++)
    {
    cout<<num[k]<<endl;
    }
    return 0;
    } // main ended
    void arrange (int*a,int*b)
    {
    if (*a>*b)
    {
    int temp=*a;
    *a=*b;
    *b=temp;
    }
    }
    If you want to be alive forever, Then DIE for others...

  2. #2
    Senior Student Adnan Ahmad Khan's Avatar
    Join Date
    Aug 2010
    Location
    Bannu/Pakisatn
    Age
    27
    Posts
    261

    Re: C++ Programs

    Copy this code,,, run on your compiler and see the Beauty of
    MATHEMATICS


    #include<iostream.h>
    #include<conio.h>
    #include<iomanip.h>
    main()
    {
    int Num=1,Multiplier=9,c=11,add=2,f=20;
    for (int i=1; i<10; i++)
    {
    int result;
    result=(Num*Multiplier)+add;
    cout<<setw(f)<<Num<<'*'<<Multiplier<<'+'<<add<<'=' <<result<<endl;
    add++;
    Num=Num+c;
    c=(c*10)+1;
    if (add==10)
    {
    f--;
    } // End of if statement
    } // End of for loop
    cout<<endl<<endl<<endl;
    cout<<"This is the BEAUTY OF MATHEMATICS.";
    getch();
    }
    If you want to be alive forever, Then DIE for others...

  3. #3
    Senior Student Adnan Ahmad Khan's Avatar
    Join Date
    Aug 2010
    Location
    Bannu/Pakisatn
    Age
    27
    Posts
    261

    Re: C++ Programs

    Here is one more program, which handles english alhabets (small/capital)....

    Check and comment....

    #include<iostream.h>
    #include<conio.h>
    #include<stdlib.h>
    void small ();
    void small_all();
    void capital();
    void capital_all();
    main()
    {
    clrscr();
    int choice;
    while (choice!=5)
    {
    cout<<"\t \t \t CHOOSE NUMBER."<<endl;
    cout<<"\t \t 1) Small English Single letter."<<endl<<
    "\t \t 2) Small English All Alphabets."<<endl<<
    "\t \t 3) Capital English Single Letter."<<endl<<
    "\t \t 4) Capital Eglish all Alphabets."<<endl<<
    "\t \t 5) EXIT."<<endl;
    cin>>choice;
    switch (choice)
    {
    case 1:
    small();
    break;
    case 2:
    small_all();
    break;
    case 3:
    capital();
    break;
    case 4:
    capital_all();
    break;
    case 5:
    exit(1);
    default:
    cout<<"Invalid Entry...! TRY AGAIN"<<endl;
    }
    }
    getch();
    } //main() ended
    void small()
    {
    int x;
    char y;
    cout<<"Enter Number of Letter :";
    cin>>x;
    y=x+96;
    cout<<"Small Letter at Place "<<x<<" is :"<<y<<endl<<endl;
    } //small() ended
    void small_all()
    {
    int x=96;
    char y;
    for (int n=1; n<=26;n++)
    {
    y=x+n;
    cout<<n<<"="<<y<<'\t';
    if (n%2==0)
    {
    cout<<endl;
    } //if ended
    } //for ended
    } //small_all() ended
    void capital()
    {
    int x;
    char y;
    cout<<"Enter Number of Letter :";
    cin>>x;
    y=x+64;
    cout<<"Capital Letter at Place "<<x<<" is :"<<y<<endl<<endl;
    } //capital() ended
    void capital_all()
    {
    int x=65;
    char y;
    for (int n=1; n<=26;n++)
    {
    y=x+n;
    cout<<n<<"="<<y<<'\t';
    if (n%2==0)
    {cout<<endl;
    } // if ended
    } //for ended
    } //capital_all() ended
    If you want to be alive forever, Then DIE for others...

  4. #4
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    yar i want your help in my studies if you can

  5. #5
    Senior Student Adnan Ahmad Khan's Avatar
    Join Date
    Aug 2010
    Location
    Bannu/Pakisatn
    Age
    27
    Posts
    261

    Re: C++ Programs

    Quote Originally Posted by fireocean View Post
    yar i want your help in my studies if you can
    So how can i help you....
    I am ready....
    If you want to be alive forever, Then DIE for others...

  6. #6
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    4- Using the double dimension arrays declare the int arrays of dimension [4][5] and take the values input at run time and find out the minimum and sort them in descending order value from those inputted values..

    plzzz make this program for me .... if you can ..

  7. #7
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    in which uni are you doing bscs

  8. #8
    Senior Student Adnan Ahmad Khan's Avatar
    Join Date
    Aug 2010
    Location
    Bannu/Pakisatn
    Age
    27
    Posts
    261

    Re: C++ Programs

    Quote Originally Posted by fireocean View Post
    in which uni are you doing bscs
    University of Science and Technology Bannu.

    Send me Ur information via Private message.

    Today i have read ur program requirements... I wil try at home...
    If you want to be alive forever, Then DIE for others...

  9. #9
    Senior Student Adnan Ahmad Khan's Avatar
    Join Date
    Aug 2010
    Location
    Bannu/Pakisatn
    Age
    27
    Posts
    261

    Re: C++ Programs

    Quote Originally Posted by fireocean View Post
    4- Using the double dimension arrays declare the int arrays of dimension [4][5] and take the values input at run time and find out the minimum and sort them in descending order value from those inputted values..

    plzzz make this program for me .... if you can ..

    SORRY FOR BEING LATE.... Yr hmaray LAB ka server down ho gya hai.....

    // This code is for compiler Turbo v4.5
    #include<iostream.h>
    void descend (int*,int*);
    main()
    {
    int num[4][5];
    cout<<"Enter Twenty Numbers :";
    for (int i=0;i<4;i++)
    {
    for (int j=0;j<5; j++)
    { //two for loops for input values
    cin>>num[i][j];
    }
    }
    int smaller=num[0][0];
    for (int row=0; row<4; row++)
    {
    for (int col=0; col<5; col++)
    {
    if (smaller>num[row][col])
    { // for finding smaller number
    smaller=num[row][col];
    }
    }
    }
    cout<<"Smaller Number Is : "<<smaller<<endl ;

    for (int pass=0; pass<20; pass++)
    {
    for (int k=0;k<4;k++) //for desecending order
    {
    for (int l=0; l<5; l++)
    {
    descend (&num[k][l],&num[k][l+1]);
    }
    }
    }
    cout<<"Descending Order Is :";
    for (int m=0; m<4; m++)
    {
    for (int n=0; n<5; n++) //to display values ....
    {
    cout<<" "<<num[m][n];
    }
    }
    cout<<endl;
    return 0;
    } // main ended
    void descend (int *num1, int *num2)
    {
    if (*num1<*num2)
    {
    int temp;
    temp=*num1;
    *num1=*num2;
    *num2=temp;
    }
    }
    If you want to be alive forever, Then DIE for others...

  10. #10
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    thamx
    As rule man is fool;
    When its hot he wants it cool;
    when its cool ;
    he wants it hot ;
    always wanting what is not ;

  11. #11
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    thank you very much
    As rule man is fool;
    When its hot he wants it cool;
    when its cool ;
    he wants it hot ;
    always wanting what is not ;

  12. #12
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    yar i cant send you pms they require 300 posts .. you just sms me om my mail fireocean39@yahoo .com space nahi ha darmian may
    As rule man is fool;
    When its hot he wants it cool;
    when its cool ;
    he wants it hot ;
    always wanting what is not ;

  13. #13
    Senior Student Adnan Ahmad Khan's Avatar
    Join Date
    Aug 2010
    Location
    Bannu/Pakisatn
    Age
    27
    Posts
    261

    Re: C++ Programs

    Its ok..... may nay email kr dya hai....
    If you want to be alive forever, Then DIE for others...

  14. #14
    Senior Student Adnan Ahmad Khan's Avatar
    Join Date
    Aug 2010
    Location
    Bannu/Pakisatn
    Age
    27
    Posts
    261

    Re: C++ Programs

    FIBONACCI SERIES USING FOR LOOP

    #include <iostream.h>
    int main ()
    {
    int a[128];
    int fN;
    int i;
    a[0]=0;
    a[1]=1;
    cout << "How many n terms do you want in the sequence: ";
    cin >> i;
    cout<<a[0]<<endl<<a[1]<<endl;
    for ( fN = 2 ; fN < i ; fN++ )
    {
    a[fN]=a[fN-1]+a[fN-2];
    cout << a[fN] <<"\n";
    }
    }
    If you want to be alive forever, Then DIE for others...

  15. #15
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    i need your help once again in oop plzzz we will share our nots etc email me some informative books of oop
    As rule man is fool;
    When its hot he wants it cool;
    when its cool ;
    he wants it hot ;
    always wanting what is not ;

  16. #16
    iTT Student
    Join Date
    Jan 2011
    Location
    chakwal
    Age
    42
    Posts
    29

    Re: C++ Programs

    Assalam o Alaikum
    adnan ahmed how r u ?
    aap ka email keya hein??
    thanks

  17. #17
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    yar fireocean39***********
    As rule man is fool;
    When its hot he wants it cool;
    when its cool ;
    he wants it hot ;
    always wanting what is not ;

  18. #18
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    opper wala post ma lika hain
    As rule man is fool;
    When its hot he wants it cool;
    when its cool ;
    he wants it hot ;
    always wanting what is not ;

  19. #19
    iTT Student
    Join Date
    May 2011
    Location
    pakistan
    Posts
    54

    Re: C++ Programs

    3ed wala post ma mera email hain
    As rule man is fool;
    When its hot he wants it cool;
    when its cool ;
    he wants it hot ;
    always wanting what is not ;

  20. #20
    iTT Student
    Join Date
    Jan 2011
    Location
    chakwal
    Age
    42
    Posts
    29

    Re: C++ Programs

    /*solution please*/

    Problem Statement: Airline Fare System
    Write a program for air fare System which will calculate fare on already reserved ticket.

    Detailed Description:

    In the program, you are required to make a class with name 'airfare' and following are the data members of class airfare.

    Seat type
    Price
    Tax
    Airline charges

    In the main () function, create a constructor of class to initialize the class data members. Class must have a destructor. Create following user defined function as discussed below along with class constructors and destructor:

    GetData(), this function will take the input for seat type variable from the user and will set the ticket price according to the input taken from user. The function GetData() will prompt user to enter required information for seat type.

    Seat Type:
    User can select one of the Seat type:

    1. First Class Seat
    2. Business Class Seat
    3. Economy Class Seat

    The function GetData() will also read the data from file named data.txt ( created in assignment no 3 ) to read the destination and then assigns the price for the given destination.


    Price:
    Price will be calculated on the basis of following information:

    1- Fare type
    2- Destination (Desire destination information will be read from the file “data.txt” )

    The price will be assigned according to the table given below:




    Seat Type Destination Ticket Price
    Economy Class Karachi 3000
    Economy Class Peshawar 2500
    Economy Class Lahore 4000
    Business Class Karachi 5000
    Business Class Peshawar 4500
    Business Class Lahore 6000
    First Class Karachi 7000
    First Class Peshawar 7000
    First Class Lahore 7000



    Airline charges:
    All airlines will charge 15% of ticket price extra to the all fare types along with the tax.

    Class should have a user-defined function named CalculateTax() to calculate the tax according to seat type and ticket price.

    Tax calculation will be done as below:

    If seat type is First class then tax will be 30% of ticket price
    If seat type is Business class then tax will be 20% of ticket price
    If seat type if Economy class then tax will be 10% of ticket price


    Calculateprice(), this member function will calculate price of already reserved ticket and will display total fare on the screen. Price calculation will add above calculated tax, airline charges to the actual ticket price according to following information.

    Fare = Airline Charges + Tax + Ticket Price


    In the function WriteData(), you are required to create a new text file name “fare.txt” in same folder/directory where you have saved your .cpp file. Open this file by using file handling functions and then write all air fare information in that file in following format.

    ------------------------------------------------------------------------
    Name | Address| Date | Destination | Flight.No | Seat.No | Fare
    ------------------------------------------------------------------------.
    .
    .
    .
    .
    .
    .
    ------------------------------------------------------------------------

    Required information of Name, Address, Date, Destination, Flight No, Seat No, should be taken from assignment no 3 output file.

    Points To Remember:

    Following points should be kept in mind and handled accordingly, otherwise marks will be deducted.

    Reading and writing from text file, must be done with standard file handling functions provided in handouts.
    All data members must be declared and initialized with appropriate data type.
    Exceptional cases must be kept in mind and handled accordingly while taking input from user.
    User must be prompted if there is any error while:

    ◦ Creating a file.
    ◦ Opening a file for reading/ writing.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •