Object Oriented Programming

Okay so I have a project where we need to have a list of clients for a consulting firm: For Client and Business Type Acme Construction, Machinery design, Johnson Electrical, Switch manufacturing, Brown Heating and cooling, Boiler design, Smith Switches, Switch manufacturing Jones Computers, Computer sales, Williams Cleaning Equipment Machinery. sales To keep track of your clients in an orderly manner, you need a program that can arrange them alphabetically by name or by business type. Write such a program using a bubble sort.
The input specifications are to: 1) Read the client and business from a file 2) Read the requirement of sorting according to name or business from the keyboard. The output specification is to put the arranged list into an output file.

This must be in C++. Here's what I have so far:

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

void swap(char c1[], char c2[])
{
char temp[100];
strcpy(temp, c1);
strcpy(c1, c2);
strcpy(c2, temp);
}
int main()
{
ifstream inFile("input.txt");
ofstream outFile("output.txt");
char client[100][100], type[100][100];
int count = 0, choice;
string str;
while(getline(inFile, str))
{
strcpy(client[count], str.c_str());
getline(inFile, str);
strcpy(type[count], str.c_str());
count++;
}
cout << "Enter 1 to sort by Client name, 2 to sort by business type and anything other to exit:";
cin >> choice;

if(choice == 1){
for(int i = 0; i < count - 1; i++){
for(int j = 0; j < count - i - 1; j++){
if(strcmp(client[j], client[j + 1]) >= 0){
swap(client[j], client[j + 1]);
swap(type[j], type[j + 1]);
}
}
}
}
else if(choice == 2){
for(int i = 0; i < count - 1; i++){
for(int j = 0; j < count - i - 1; j++){
if(strcmp(type[j], type[j + 1]) > 0){
swap(client[j], client[j + 1]);
swap(type[j], type[j + 1]);
}
}
}
}
for(int i = 0; i < count; i++){
string str1(client[i]);
string str2(type[i]);
outFile << str1 << "\n" << str2 << "\n\n";
}
cout << "Please check the output file 'output.txt' for the sorted results\n";
return 0;
}

Using Microsoft Visual to do the program. I get an error that the system cannot find the file specified. I added the input.txt in the file, what did I do wrong?


It sounds like VS cannot find your file. If you use an absolute path that can solve it, or you could try to change the default root dir
https://msdn.microsoft.com/en-us/library/ms171340%28v=vs.90%29.aspx
Topic archived. No new replies allowed.