I need to create a separate cpp file to pull a function from, my book and power point slide don't go into much detail on this. Please help.
"Include at least one function in a separate .cpp file."
Code:
#include<iostream>
#include<iomanip>
#include<fstream>
#include<limits>
usingnamespace std;
int main()
{
char again;// assigned variable for run again loop
do
{
int n;//n=number of computers
int conn;// conn= total of connections
cout <<"\t*********************************;
cout <<******************************\n";
cout <<"\t*This program will display a list;
cout << of how many possible network*\n";
cout <<"\t*connections you could have;
cout << given any number of computers.*\n";
cout <<"\t*********************************;
cout <<******************************\n";
cout <<"\n";
cout <<"Enter the maximum number of computers\n";
cout <<for which you would like to;
cout <<calculate total connections:";
cin >> n;
//validate the input
while(!cin || n <2)
{
//Explain the invalid input.
cin.clear();
cin.ignore(numeric_limits <streamsize>::max(),'\n');
cout <<"You must enter a number range from 2-10\n";
cout <<"Please enter your selection again: \n";
cin >> n;
}
//Block that will open file, write to file, and display to the console
cout <<"\n";
ofstream myFile;
myFile.open("totalComputers.txt");
cout <<"Number of Computers\tTotal Connections\n";
myFile <<"Number of Computers\tTotal Connections\n";
cout <<"////////////////////////////////////////\n";
myFile <<"////////////////////////////////////////\n";
for(int count=2; count <= n; count++)
{
conn = count *(count -1)/2;
cout << setw(10)<< count << setw(24)<< conn << endl;
myFile << setw(10)<< count << setw(24)<< conn << endl;
}
//This was implemented to close the file,
//and notify user that data write is complete.
myFile.close();
cout <<"\n";
cout <<"The data file has finished writing.\n";
//This will allow the user to run the program again or exit the program
cout <<"\n";
cout <<"Would you like to run the program again? y or n\n";
cin >> again;
}while(again =='y');
cout <<"Have a great day, please press any key to exit.\n";
return0;
}