Help? Circular Dependency error

Okay so we have a project where we need to have a list of clients for a consulting firm: For Clientand 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.


The code I have:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
/nged list into an output file.

 
void bubbleSort(string arrayToSort[], string secondArray[], int n);
void Display (string client[], string business[], int n);
 
int _main(){
 
const int N=10; //Max number of records.
 
int count=0; //Number of records on file count.
 
string clients[N]; //Client Array
 
string business[N]; //Business Array
 
char filename[] = "inputfile.txt"; //the input for business and client
 
ifstream fin;
 
fin.open(filename); //open file to read information
 
//loop to read records from file
 
while(getline(fin,clients[count])) //read client name
 
{
 
getline(fin,business[count]); //read business
 
count++; //incvcrement count
 
}
 
fin.close(); //close file
 
char ch; //user selection
 
do
 
{
 
cout<<endl;
 
cout<<"1. Sort by Client name" <<endl;
 
cout<<"2. Sort by Business" <<endl;
 
cout<<"3. Display Records" <<endl;
 
cout<<"0. Exit" <<endl;
 
cout<<"Enter your option: ";
 
cin>>ch;
 
switch(ch)
 
{
 
case '1':
 
bubbleSort(clients, business, count);
 
break;
 
 
 
case '2':
 
bubbleSort(business, clients, count);
 
break;
 
case '3':
 
Display(clients, business, count);
 
break;
 
case '0':
 
break;
 
default:
 
cout<<"You have entered a wrong choice. Try again." <<endl;
 
}
 
}
 
 
 
while(ch!='0');
 
return 0;
 
}
 
void bubbleSort(string arrayToSort[], string secondArray[], int n)
 
{
 
bool swapped = true;
 
int j = 0;
 
string tmp;
 
 
 
while (swapped)
 
{
 
swapped = false;
 
j++;
 
for (int i = 0; i < n - j; i++)
 
{
 
if (arrayToSort > arrayToSort[i + 1])
 
{
 
tmp = arrayToSort;
 
arrayToSort = arrayToSort[i + 1];
 
arrayToSort[i + 1] = tmp;
 
tmp = secondArray;
 
secondArray = secondArray[i + 1];
 
secondArray[i + 1] = tmp;
 
swapped = true;
 
}
 
}
 
}
 
}
 
void Display (string client[], string business[], int n)
 
{
 
cout<<"CLIENT	 BUSINESS"<<endl;
 
cout<<"--------------------------"<<endl;
 
for(int i=0; i<n; i++)
 
{
 
cout<<client<<"\t\t"<<business<<endl;
 
}
 
}


Where am I going wrong?
Last edited on
Try using code tags so we can read it thx...
What kind of error(s) are you getting ?
What is being printed and what should be printed ?
There is a list for taken from an input file.
Read the client and business from a file.
Read requirement of sorting according to name or business from the keyboard.
Then the output is to be put and arranged list to be arranged into an output file.

I am trying to compile and print to an output file and it keeps throwing a circular dependency error.
OK.
The compilation errors have to do with the BubbleSort function. For example, line 130 if(arrayToSort > arrayToSort[i + 1]) is unable to make this comparison because it's not comparing 2 elements of 'arrayToSort[]' but rather 1 element with the address of its pointer in memory which the compiler will flag as an error. I'm guessing u want this if(arrayToSort[i] > arrayToSort[i + 1]).

All of those arrayToSort need to be fixed similarly. Also, I'll point out that strings are typically not compared with > < operators. To sort things alphabetically, one idea is to find the ascii numeric values of the letters and then compare the numeric values of the first letters of 2 strings to see which is lower - if the letters are the same, test the 2nd letter of each and so on.

Given that ur input file is like this:
Acme Construction
Machinery design
Johnson Electrical

Lines 30 and 34 are not going to work as u want. getline takes the full line and stores it into the string. So in this case,
element 0 of clients[count] will contain "Acme Construction"
element 0 of business[count] will contain "Machinery design"
element 1 of clients[count] will contain "Johnson Electrical"

To fix that u can have a 'parser' string to contain the whole line and then parse it and store it into the appropriate arrays. Another option is to use the insertion operator from ifstream >> like:
fin >> clients[count] >> business[count];
as many times as needed. This will only work as long as the input file is always exactly in the same format.

Last edited on
Topic archived. No new replies allowed.