Quick question... how do you pass a list in to a function...
For example forvoid reverseListwhat would the parameters be
for my function... I'm trying to put everything in my case R statement in
a function so I can make a neat class...
#include <iostream>
#include <list>
#include <cstdlib>
#include <conio.h>
usingnamespace std;
void reverseList();
void sortList();
void removeData();
void clearData();
char getPick();
int main(){
list<double> numbers; // declares the list
list<double>::iterator ip;
bool run = true;
cout << "============List Program(v2)===========\n" << endl;
for(int i = 1; i < 11; i++) numbers.push_back(i*10);
cout << "The original list:";
for(ip = numbers.begin(); ip != numbers.end(); ip++) // outputs list contents
cout << ' ' << *ip;
do{
switch(getPick()){
case'R':{system("cls"); // reversing the list
numbers.reverse();
cout << "List reversed:";
for(ip = numbers.begin(); ip != numbers.end(); ip++)
cout << ' ' << *ip;
}break;
case'S':{system("cls"); // sorting the list
numbers.sort();
cout << "List sorted:";
for(ip = numbers.begin(); ip != numbers.end(); ip++)
cout << ' ' << *ip;
}break;
case'D':{system("cls"); // removing numbers from the list
int n;
double num;
cout << "Current list:";
for(ip = numbers.begin(); ip != numbers.end(); ip++)
cout << ' ' << *ip;
cout << "\n\nHow many numbers do you want to delete: "; cin >> n;
if(n < 2)
cout << "What number do you want deleted:\n";
else
cout << "What numbers do you want deleted:\n";
for(int i = 0; i < n; i++){
cin >> num;
numbers.remove(num);
}
system("cls");
cout << "The list has the numbers:";
for(ip = numbers.begin(); ip != numbers.end(); ip++)
cout << ' ' << *ip;
}break;
case'C':{system("cls"); // clearing & adding to the list
int l;
double num;
numbers.clear();
cout << "How many numbers do you want to add: "; cin >> l;
cout << "Enter new number(s):\n";
for(int i = 0; i < l; i++){
cin >> num;
numbers.push_back(num); // starts from first digit entered
//numbers.push_front(num); // starts from the last digit entered
}
system("cls");
cout << "The list now contains:";
for(ip = numbers.begin(); ip != numbers.end(); ip++)
cout << ' ' << *ip;
}break;
case'E':{system("cls"); // checking to see if the list is empty
double sum(0);
while (!numbers.empty()){
sum += numbers.front();
numbers.pop_front();
}
cout << "Total: " << sum << endl;
}break;
case'Q': run = false; break;
default: cout << "That's not a valid choice!" << endl; break;
}
}while(run);
system("cls");
cout << "\nAu revoir!!!" << endl;
return 0;
}
char getPick(){ // user picks how to manipulate the list
char pick;
cout << "\n\nWhat would you like to do?";
cout << "\n(R)everse, (S)ort, (D)elete, (C)lear, (E)mpty, (Q)uit" << endl;
pick = getch();
return toupper(pick);
}