Linking/Sorting Vectors in C++ So I need to make a bank program where the user i
ID: 3863320 • Letter: L
Question
Linking/Sorting Vectors in C++
So I need to make a bank program where the user is allowed to input as many accounts as they want, have the ability to sort based on descending account number, and have the accounts printed back, etc.
My program has been working (mostly) so far, and the main issue that I'm trying to tackle is that each of the inputs for an account are stored as vectors. So I have a string vector for the account name, and double vectors for the account number and balance.
My real question is how do I "link" these? When I sort the accounts based on account number, the same sorting isn't happening for the account balance and the names. To sum it up, the account numbers must be sorted, and the account balance and name must also be sorted the same as the account number.
Likewise, what would be the best way to print these accounts? Are pointers used? Here is my current code:
int main declare list of account here. The size of the list is not fixed int input 0; int input Ptr & input while input 6) menu (input Ptr run loop to continue program until terminated by user switch input cases: call functions to perform tasks case 1: make Account break case 2: Print AllAccount break case 3: deposit Account break case 4: withdrawAccount break case 5: print Account break; case 6: breakExplanation / Answer
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector< pair <int,int> > vect;
int arr[] = {10, 20, 5, 40 };
int arr1[] = {30, 60, 20, 50};
int n = sizeof(arr)/sizeof(arr[0]);
for (int i=0; i<n; i++)
vect.push_back( make_pair(arr[i],arr1[i]) );
for (int i=0; i<n; i++)
{
cout << vect[i].first << " "
<< vect[i].second << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
vector< pair <int,int> > vect;
int arr[] = {10, 20, 5, 40 };
int arr1[] = {30, 60, 20, 50};
int n = sizeof(arr)/sizeof(arr[0]);
for (int i=0; i<n; i++)
vect.push_back( make_pair(arr[i],arr1[i]) )
cout << "The vector before sort operation is: " ;
for (int i=0; i<n; i++)
{
cout << vect[i].first << " "
<< vect[i].second << endl;
}
sort(vect.begin(), vect.end());
cout << "The vector after sort operation is: " ;
for (int i=0; i<n; i++)
cout << vect[i].first << " "
<< vect[i].second << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector< pair <int,int> > vect;
int arr[] = {10, 20, 5, 40 };
int arr1[] = {30, 60, 20, 50};
int n = sizeof(arr)/sizeof(arr[0]);
for (int i=0; i<n; i++)
vect.push_back( make_pair(arr[i],arr1[i]) );
for (int i=0; i<n; i++)
{
cout << vect[i].first << " "
<< vect[i].second << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
vector< pair <int,int> > vect;
int arr[] = {10, 20, 5, 40 };
int arr1[] = {30, 60, 20, 50};
int n = sizeof(arr)/sizeof(arr[0]);
for (int i=0; i<n; i++)
vect.push_back( make_pair(arr[i],arr1[i]) )
cout << "The vector before sort operation is: " ;
for (int i=0; i<n; i++)
{
cout << vect[i].first << " "
<< vect[i].second << endl;
}
sort(vect.begin(), vect.end());
cout << "The vector after sort operation is: " ;
for (int i=0; i<n; i++)
cout << vect[i].first << " "
<< vect[i].second << endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.