Quick Search for:  in language:    
simple,highscore,system,with,explanation,work
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
C/ C++ Stats

 Code: 715,766. lines
 Jobs: 107. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for C/ C++.
Click here to see a screenshot of this code!Button Game
By L!xy on 1/29

(Screen Shot)

SimpleService
By Gaidar Magdanurov on 1/29


ip2bin
By Joe Sloan on 1/29


Click here to see a screenshot of this code!c++ basic all
By Hamdi Farah on 1/28

(Screen Shot)

biopro.c --- search for words that do not exist in the dictionary file
By Donald Bono on 1/28


BruteForce Engine
By koby-GR on 1/28


Catch Me If U Can !!
By ashish & manas on 1/27


nOS ver 1.0
By - Snake - on 1/27


WordInFile.c -- look up a dictionary file for the word you just entered (source code only)
By Donald Bono on 1/27


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Highscore

Print
Email
 
VB icon
Submitted on: 12/28/2003 10:40:58 PM
By: Evan Knight 
Level: Beginner
User Rating: Unrated
Compatibility:C++ (general)

Users have accessed this code 288 times.
 

(About the author)
 
     This is a simple highscore system with an explanation of how it works. With minor editing you can implement it into your own program.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

//**************************************
//     
// Name: Highscore
// Description:This is a simple highscor
//     e system with an explanation of how it w
//     orks. With minor editing you can impleme
//     nt it into your own program.
// By: Evan Knight
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=7348&lngWId;=3//for details.//**************************************
//     

//Programed by Evan
//12/15/03
//This is a highscore program. It saves 
//     a seperate file on your computer to keep
//     
//the high scores saved. Can be implemen
//     ted into a program with some minor chang
//     es.
#include <iostream> //standard header
#include <fstream> //used for ifstream
using namespace std;
struct data //Data Abstraction, each variable holds this info.
    {char name[20]; //20 characters for a name
    int score;}; //score
    void score(data[],int,data); //pass array a, how many elements in a,array b into
    //score function
    int main()
        {data a[5],b; //initalize variable a[5] with data type data, and b with data
        ifstream ReadIn; //call the read in function(ifstream) and name(Readin) it.
        ReadIn.open("highscore.dat"); //open file highscore.dat
        if (ReadIn.fail()) //if highscore.dat doesn't exist
            {
            cout<<"File highscore.dat not found!\nCreating blank high score.\n";
            data temp[5]={{"Evan",0}, //creates temp function and initializes
                {"Evan",0}, //all elements with "Evan",0.
                    {"Evan",0},
                        {"Evan",0},
                            {"Evan",0}};
                            	ofstream fout("highscore.dat"); //fout writes to highscore.dat
                            	for (int i=0;i<5;i++) //loop
                            	fout<<temp[i].name<<" "<<temp[i].score<<endl; //write blank list to file
                            	fout.close(); //no longer need fout, so it's gone
                            for (int i=0;i<5;i++)
                            a[i]=temp[i]; //make a[5] equal to temp[5]
                        }

else //if highscore.dat does exist for (int i=0;i<5;i++) ReadIn>>a[i].name>>a[i].score; //read highscore.dat into program for (int i=0;i<5;i++) cout<<i+1<<". "<<a[i].name<<" "<<a[i].score<<endl; //print highscore list cout<<"Please enter name for new highscore: "; cin>>b.name; cout<<"Please enter score for highscore: "; cin>>b.score; score(a,5,b); //call score function, pass in values data a,int 5,data b. for (int i=0;i<5;i++)//int 5=number of elements in array a cout<<i+1<<". "<<a[i].name<<" "<<a[i].score<<endl; //print highscore list ofstream fout("highscore.dat"); //call the read out function(ofstream) and for (int i=0;i<5;i++)//name(fout) it. fout<<a[i].name<<""<<a[i].score<<endl; //read out highscore list into file fout.close(); //no need for fout anymore return 0;//end program }
void score(data a[],int d,data b) { data temp; //need temp data for switching if (b.score>a[4].score) //if b.score is bigger than a[4].score {a[4]=b; //make the last score of the list equal to b(score just entered) for (int i=d-1;i>0;i--) //now that the score is on the list, just check and sort if (b.score>a[i-1].score) {temp=a[i]; //switch - if the 5th spot is bigger than a[i]=a[i-1]; //the 4th spot,switch. if 4th spot is bigger a[i-1]=temp;} //than 3rd spot, switch. etc... }
}


Other 2 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | C/ C++ Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.