CODE
#include <iostream>
#include <string>
using namespace std;
struct recordType
{
string name;
int score;
};
void GetInput(int &input, int &size);
void GetData(recordType * &data, int &size);
void PrintHighest(recordType * &data, int &size);
void Search(recordType * &data, int &size);
void main(void)
{
int input=0, size=0, temp=0;
recordType *data;
while(input!=4)
{
GetInput(input, size);
switch(input)
{
case 1: GetData(data, size);
break;
case 2: PrintHighest(data, size);
break;
case 3: Search(data, size);
break;
case 4: break;
default: return;
}
}
}
void GetInput(int &input, int &size)
{
cout << "[Score Borad] " << size << " records" << endl;
cout << "1. Enter data" << endl;
cout << "2. Highest Score" << endl;
cout << "3. Search" << endl;
cout << "4. Exit" << endl;
for(bool check_input=false; check_input==false; )
{
cout << "Choice: ";
cin >> input;
if(!cin)
{
cin.clear();
cin.ignore(100, '\n');
cout << "Invalid choice." << endl;
}
else if(input<=(-1) || input>=7)
{
cout << "Invalid choice." << endl;
}
else
{
check_input=true;
}
}
}
void GetData(recordType * &data, int &size)
{
if(size!=0)
{
// Copy current data into temporary data
// Delete current data
recordType *temp_data = new recordType[size];
for(int i=0; i<size; i++)
{
temp_data[i].name = data[i].name;
temp_data[i].score = data[i].score;
}
delete [] data;
// Copy temporary data into new data
// Delete temporary data
data = new recordType[++size];
for(int i=0; i<(size-1); i++)
{
data[i].name = temp_data[i].name;
data[i].score = temp_data[i].score;
}
delete [] temp_data;
}
else
{
data = new recordType[++size];
}
cout << "Enter Name: ";
cin >> data[size-1].name;
for(bool check_score=false; check_score==false; )
{
cout << "Enter Score: ";
cin >> data[size-1].score;
if(!cin)
{
cin.clear();
cin.ignore(100, '\n');
cout << "Numeric input required." << endl;
}
else
{
check_score=true;
}
}
cout << endl;
}
void PrintHighest(recordType * &data, int &size)
{
int temp_highest=0, firstPlace=0;
if(size==0)
{
cout << "Please enter data before getting highest score." << endl << endl;
}
else
{
for(int i=0; i<size; i++)
{
// If temp_highest is smaller, change it bigger
if(data[i].score>=temp_highest)
{
temp_highest = data[i].score;
firstPlace=i;
}
}
cout << "The highest score is " << data[firstPlace].score;
cout << " by " << data[firstPlace].name << "." << endl << endl;
}
}
void Search(recordType * &data, int &size)
{
string getTerm;
unsigned int count;
cout << "Enter search term: ";
cin >> getTerm;
cout << "Search results:" << endl;
for(int i=0; i<size; i++)
{
if(data[i].name.find(getTerm)!= string::npos)
cout << data[i].name << " (" << data[i].score << ")" << endl << endl;
}
}
hi i need help as i wan my high score to just show out by itself but not by typing out. Do you have any tutorials on high sore input? It will be a great help to me .Thanks.