[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

SIMPLE ASCENDING SORT, EXIT,FLOAT..... NEWBIE

Asked by samkhool4u in C++ Programming Language

Tags: ascending, gotoxy, meaning, sort

i posted this question and i got replies which solved my problem... partly
here is the link
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20646266.html
i am bringing this up because i deparately need a solution.
thanks for all ur efforts..
   
 i tried to impliment  reborn_assassin's program in to my program which is below
----------------------------------------------------------------------------------------------------------------------------------------------------------------

// AUTHOR--SAM
#include <iostream.h>
#include <fstream.h>

#include <conio.h>
//include <stdlib.h>



fstream datafile;
// declaring the file object so that it can communicate with the operating system

    int max=0,min=9999,i;
    float ave,sum2;
    long sum=0;
    int* contents;  // declares variable to read data from file
    char filename[16],words[80];
    double input;
    int keypress,anykey, count=0;

    void exit_prog()
    {
     cout<<"program terminated"<<endl;


    }
 //------------------- Welcom Screen Function-------------------//
    int welcome()
{
    gotoxy(15,5);
    cout<<"****************************************";
    gotoxy(15,6);
    cout<<"*\t\t   ------- COLLEGE\t     *";
    gotoxy(15,7);
    cout<<"*\t        FILE PROCESSING SYSTEM          *";
    gotoxy(15,8);
    cout<<"*\t\t PRESS C TO CONTINUE\t     *";
    gotoxy(15,9);
    cout<<"*                                      *";
    gotoxy(15,10);
    cout<<"****************************************";
    gotoxy(34,9);
    keypress=getche();
    stop:

return 0;
}
//----------------------Menu Screen Function----------------------//
int menu()
{  clrscr();
    gotoxy(15,5);
    cout<<"****************************************"<<endl;
    cout<<"\t      *\t\tFile Processing System\t     *"<<endl;
    cout<<"\t      *     \t  Please input option        *"<<endl;
    cout<<"\t      *                            \t     *"<<endl;
    cout<<"\t      * 1----------Create new data file      *"<<endl;
    cout<<"\t      * 2----------Input data to a file      *"<<endl;
    cout<<"\t      * 3----------View numbers form a file  *"<<endl;
    cout<<"\t      * 4----------Display maximum\t     *"<<endl;
    cout<<"\t      * 5----------Display minimum\t     *"<<endl;
    cout<<"\t      * 6----------Display total\t     *"<<endl;
    cout<<"\t      * 7----------Display the Average value *"<<endl;
    cout<<"\t      * 8----------Ascending sort \t     *"<<endl;
    cout<<"\t      * 9----------EXIT  \t\t     *"<<endl;
    cout<<"\t      *                            \t     *";
    gotoxy(15,18);
    cout<<"****************************************"<<endl;
    gotoxy(34,8);
    keypress=getche();

return 0;
}
//-------------OPTION 1 CREATE FILE---------------------------//
int create_file()
{
    // asking user to input name of the file to create
 cout<<"please enter the name of the file that you wish to create"<<endl;
 cout<<"use .txt as your file extension\n";

 cin>>filename;
 cout<<"\nA file named "<<filename<<" was created"<<endl;
 datafile.open(filename,ios::out);

 datafile.close(); // close file
return 0;
}


//-------------OPTION 2 INPUT DATA TO A FILE---------------------------//
int input_data()
{

// asking user to input name of the file to input data to
 cout<<"please enter the name of the file that you wish to input data to"<<endl;
 cout<<"please use the correct extension\n";

 cin>>filename;

     do
     {
         count++;
         datafile.open(filename,ios::app);
         clrscr();
         cout<<"input number";
         cin>>input;
         datafile<<input<<endl;
         datafile.close();
         cout<<("do you want to input another number... press anykey to continue or N to exit\n");

         keypress=getch();

         }while(keypress!=110&&keypress!=78);

         clrscr ();
         cout<<"You entered "<<count<<" numbers\n"<<endl;

return 0;

}
//-------------OPTION 3 VIEW DATA FORM A FILE---------------------------//
int view_file()
{

      // asking user to input name of the file from which the data needs to reviewed
 cout<<"please enter the name of the file which you wish to view the contents"<<endl;
 cout<<"please use the correct extension\n";
 cin>>filename;
    datafile.open(filename,ios::in);      // open numbers.txt file for reading

     while(!datafile.eof())  // keeps reading till the end of file
     {
         datafile.getline(words,80,'\n'); // read character by character form file ito words

         cout<<words<<endl;    // displays characters on the screen

     };

     datafile.close(); // close file
return 0;
};
//-------------OPTION 4 Maximum---------------------------//

int maximum()
{         contents= new int[count];
    datafile.open(filename,ios::in);      // opens numbers.txt file for reading
// displaying the contents of the file
    for(i=0;i<count;i++)  // keeps reading till the end of file
     {
         datafile>>contents[i]; // read character by character form file  ito words

         cout<<contents[i]<<endl;    // displays characters on the screen

     };

 // find and display max
    for(i=0;i<count;i++)
    {
                   if(contents[i]>max)
                        max=contents[i];
    }
    cout<<"max is "<<max<<"\n";

 datafile.close();
return 0;
}
//-------------OPTION 5 MINIMUM---------------------------//
int minimum()
{     contents= new int[count];
    datafile.open(filename,ios::in);      // opens numbers.txt file for reading
// displaying the contents of the file
    for(i=0;i<count;i++)  // keeps reading till the end of file
     {
         datafile>>contents[i]; // read character by character form file  ito words

         cout<<contents[i]<<endl;    // displays characters on the screen

     };
    //find and display min
    for(i=0;i<count;i++)
    {
         if(contents[i]<min)
              min=contents[i];
     }
     cout<<"min is "<<min<<endl;
 datafile.close(); // close file
    return 0;
}





//-------------OPTION 6 TOTAL---------------------------//
int total()
{
      contents= new int[count];
    datafile.open(filename,ios::in);      // opens numbers.txt file for reading
// displaying the contents of the file
    for(i=0;i<count;i++)  // keeps reading till the end of file
     {
         datafile>>contents[i]; // read character by character form file  ito words

         cout<<contents[i]<<endl;    // displays characters on the screen

     };
 // calcualte and display sum
    for(i=0;i<count;i++)
         sum=sum+contents[i];

    cout<<"sum is "<<sum<<"\n";

    datafile.close(); // close file
return 0;
}

//-------------OPTION 7 AVERAGE---------------------------//
int average()
{     contents= new int[count];
    datafile.open(filename,ios::in);      // opens numbers.txt file for reading
// displaying the contents of the file
    for(i=0;i<count;i++)  // keeps reading till the end of file
     {
         datafile>>contents[i]; // read character by character form file  ito words

         cout<<contents[i]<<endl;    // displays characters on the screen

     };
    // calclate and display average
    sum=sum2;
    ave=sum2/count;
    cout<<"average is "<<ave<<endl;
    datafile.close(); // close file
return 0;
}
//-------------OPTION 8 SORT---------------------------//
int sort()
{
         char ans;
         contents= new int[count];
         int tp, i, j, total;
         total =  sizeof(contents)/4; // Meaning you can change the size of the array
         for (i=1; i<=total-1; i++)
              {
              for (j=i+1; j<=total; j++)
                   {
                     if (contents[i] > contents[j])
                        {
                              tp = contents[i];
                              contents[i] = contents[j];
                              contents[j] = tp;
                        }
                   }
              }
     for (i=1; i<=total; i++)
                   cout << endl << contents[i];
     cin >> ans;

return 0;
}


//-------------MAIN PROGRAM---------------------------//

int main()
{

    welcome();
    while(keypress!=67||keypress!=99)
    {
         if (keypress==99||keypress==67)
         {
              menu();
              while(keypress!=49||keypress!=50||keypress!=51||keypress!=52||keypress!=53||
                        keypress!=54||keypress!=55||keypress!=56||keypress!=57)
              {
                   if(keypress==49||keypress==50||keypress==51||keypress==52||keypress==53||
                        keypress==54||keypress==55||keypress==56||keypress==57)
                        {
                             if(keypress==49)
                                  {            //----- OPTION 1------//
                                       clrscr();
                                       create_file();
                                       cout<<"\n\n\t\t\tPress Any Key To Return to Main Menu";
                                       anykey=getch();
                                   }
                             if(keypress==50)
                                  {          //----- OPTION 2------//
                                  clrscr();
                                  input_data();
                                  cout<<"\n\n\t\t\tPress Any Key To Return to Main Menu";
                                  anykey=getch();
                                  }
                             if(keypress==51)
                                  {            //----- OPTION 3------//
                                  clrscr();
                                  view_file();
                                  cout<<"\n\n\t\t\tPress Any Key To Return to Main Menu";
                                  anykey=getch();
                                  }
                             if(keypress==52)
                                  {            //----- OPTION 4------//
                                  clrscr();
                                  maximum();
                                  cout<<"\n\n\t\t\tPress Any Key To Return to Main Menu";
                                  anykey=getch();
                                  }
                             if(keypress==53)
                                  {           //----- OPTION 5------//
                                  clrscr();
                                  minimum();
                                  cout<<"\n\n\t\t\tPress Any Key To Return to Main Menu";
                                  anykey=getch();
                                  }
                             if(keypress==54)
                                  {           //----- OPTION 6------//
                                  clrscr();
                                  total();
                                  cout<<"\n\n\t\t\tPress Any Key To Return to Main Menu";
                                  anykey=getch();
                                  }
                             if(keypress==55)
                                  {          //----- OPTION 7------//
                                  clrscr();
                                  average();
                                  cout<<"\n\n\t\t\tPress Any Key To Return to Main Menu";
                                  anykey=getch();
                                  }
                             if(keypress==56)
                                  {         //----- OPTION 8------//
                                  clrscr();
                                  sort();
                                  cout<<"\n\n\t\t\tPress Any Key To Return to Main Menu";
                                  anykey=getch();
                                  }
                             if(keypress==57)
                                  {        //----- OPTION 9------//
                                  clrscr();
                                  cout<<"\a"<<endl;
                                  cout<<"Thank you for using our program"<<endl;
                                  cout<<"We hope you enjoyed it";

                                  cout<<"\n\n\t\t\tPress Any Key exit the program";
                                  anykey=getch();
                                  break;

                                                       //exit(0);
                                  }

                         }


                   cout<<"\a";
                   clrscr();
                   menu();
              }// end while of menu validation
         }

         cout<<"\a";
         clrscr();
         welcome();

    }//end while of welcome validation

return 0;
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
there are 3 problem with my program...
1) the sort code provided by reborn_Assasin---- i ttried but i could'nt integrate his proram into mine.. i tried to look for the problem but iam having difficulty.
2) the exit function dosent work..  in the opt9.. i tried to puta  break; but  it only goes back to the welcome screenn. .
also i tried to put exit(0);  there fore included stdlib.h as header.. but for no apparent reason it gives me  9 errors.. . please could soemone  provide me with a solution for this.
3) the average option---.  initially  my ave was an int .which gave me an int value. .but when i changed it to float .all it gives me is 0..(i wanted a decimal value)
 please help
 thank you..
 
Related Solutions
 
Loading Advertisement...
 
[+][-]06/15/03 01:48 PM, ID: 8727987Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C++ Programming Language
Tags: ascending, gotoxy, meaning, sort
Sign Up Now!
Solution Provided By: Exceter
Participating Experts: 1
Solution Grade: A
 
[+][-]06/15/03 01:49 PM, ID: 8727991Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/15/03 03:38 PM, ID: 8728294Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/16/03 10:31 AM, ID: 8733490Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/16/03 11:42 AM, ID: 8734088Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/16/03 12:25 PM, ID: 8734411Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/16/03 01:12 PM, ID: 8734795Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06/17/03 06:00 AM, ID: 8739977Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/17/03 06:02 AM, ID: 8739991Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/17/03 06:21 AM, ID: 8740141Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92