Я должен написать программу, которая создает массив с 10 структурами.Это должно позволить пользователю вводить данные в массив, изменять содержимое любого элемента и отображать все данные, хранящиеся в массиве.Должен быть управляемый меню пользовательский интерфейс.У меня должна быть функция, позволяющая пользователю искать в массиве структур имя покупателя.Он должен принять часть имени клиента в качестве аргумента, а затем искать учетную запись с именем, которое ему соответствует.Все учетные записи, которые соответствуют, должны отображаться.Если ни одна учетная запись не совпадает, должно появиться сообщение о том, чтоЯ пытался написать функцию, но у меня возникли некоторые проблемы.Я все еще новичок в C ++, и мой учебник не очень полезен.Функция void findAccountInfo.Когда я запускаю свою программу, она не предлагает пользователю выполнить поиск по имени.Я не уверен, что мне не хватает.Я опубликую свой код ниже.
#include <iostream>
#include<string>
using namespace std;
struct customerAccount
{
string name, address, city, state, zip, phone;
double account_balance;
string last_payment_date;
};
void menu()
{
cout << "\n MENU " << endl;
cout << "1. Enter new customer information" << endl;
cout << "2. Change customer information" << endl;
cout << "3. Display all customer information" << endl;
cout << "4. Exit" << endl;
}
void createNewAccount(struct customerAccount cus_arr[], int index)
{
cout << "\nCustomer name: ";
cin.ignore();
getline(cin, cus_arr[index].name);
cout << "Customer address: ";
getline(cin, cus_arr[index].address);
cout << "City: ";
getline(cin, cus_arr[index].city);
cout << "State: ";
getline(cin, cus_arr[index].state);
cout << "ZIP Code: ";
getline(cin, cus_arr[index].zip);
cout << "Telephone: ";
getline(cin, cus_arr[index].phone);
cout << "Account balance: ";
cin >> cus_arr[index].account_balance;
if (cus_arr[index].account_balance < 0)
{
cout << "Account balance cannot be negative. Please re-enter account balance: " << endl;
cin >> cus_arr[index].account_balance;
}
cout << "Date of last payment: ";
cin.ignore();
getline(cin, cus_arr[index].last_payment_date);
cout << "You have entered information for customer";
cout << " number " << index << endl;
}
void changeAccountInfo(struct customerAccount cus_arr[], int cus_num, int size)
{
if (cus_num < 0 || cus_num > size)
{
cout << "Invalid Customer Number!" << endl;
}
else
{
cout << "\nCustomer name: " << cus_arr[cus_num].name << endl;
cout << "Customer address: " << cus_arr[cus_num].address << endl;
cout << "City: " << cus_arr[cus_num].city << endl;
cout << "State: " << cus_arr[cus_num].state << endl;
cout << "ZIP Code: " << cus_arr[cus_num].zip << endl;
cout << "Telephone: " << cus_arr[cus_num].phone << endl;
cout << "Account balnace: " << cus_arr[cus_num].account_balance << endl;
cout << "Date of last payment: " << cus_arr[cus_num].last_payment_date << endl;
cout << endl;
cout << "Edit the account information of the ";
cout << "customer " << cus_num << endl;
cout << "\nCustomer name: ";
cin.ignore();
getline(cin, cus_arr[cus_num].name);
cout << "Customer address: ";
getline(cin, cus_arr[cus_num].address);
cout << "City: ";
getline(cin, cus_arr[cus_num].city);
cout << "State: ";
getline(cin, cus_arr[cus_num].state);
cout << "ZIP Code: ";
getline(cin, cus_arr[cus_num].zip);
cout << "Telephone: ";
getline(cin, cus_arr[cus_num].phone);
cout << "Account balance: ";
cin >> cus_arr[cus_num].account_balance;
cout << "Date of last payment: ";
cin.ignore();
getline(cin, cus_arr[cus_num].last_payment_date);
cout << "Account information for customer " << cus_num << " has been updated." << endl;
}
}
void displayAccountInfo(struct customerAccount cus_arr[], int size)
{
for (int i = 0; i < size; i++)
{
cout << "\nCustomer name: " << cus_arr[i].name << endl;
cout << "Customer address: " << cus_arr[i].address << endl;
cout << "City: " << cus_arr[i].city << endl;
cout << "State: " << cus_arr[i].state << endl;
cout << "ZIP Code: " << cus_arr[i].zip << endl;
cout << "Telephone: " << cus_arr[i].phone << endl;
cout << "Account balnace: " << cus_arr[i].account_balance << endl;
cout << "Date of last payment: " << cus_arr[i].last_payment_date << endl;
}
cin.ignore();
cout << "\nPress enter to continue..." << endl;
if (cin.get() == '\n')
{
return;
}
}
Это функция, с которой у меня проблемы
void findAccountInfo(struct customerAccount cus_arr[], customerAccount cus_acc_arr)
{
int index = 0;
int cuss_num = 0;
string searchName = "";
bool found = false;
cout << "Enter a name (partial or full) to search for: ";
cin.ignore();
getline(cin, searchName);
for (index = 0; index < cuss_num; index++)
{
if (cus_arr[index].name.find(searchName) != string::npos)
{
cout << "Account Name:" << (index + 1) << "" << cus_arr[index].name << "\n";
found = true;
}
}
if (found == true)
{
cout << "Enter account id:";
cin >> cuss_num;
}
else
{
cout << "This name was not found in the database";
}
return;
}
Остальная часть моего кода
int main()
{
int choice = 0;
int i, f = 0;
i = 0;
int cus_num = 0;
customerAccount cus_acc_arr[20];
menu();
cout << "Please enter a choice: ";
cin >> choice;
while (true)
{
switch (choice)
{
case 1:
createNewAccount(cus_acc_arr, i);
i++;
break;
case 2:
cout << "Enter a customer number to ";
cout << "change the account ";
cout << "information:" << endl;
cout << "Customer number: ";
cin >> cus_num;
changeAccountInfo(cus_acc_arr, cus_num, i);
break;
case 3:
displayAccountInfo(cus_acc_arr, i);
break;
case 4:
system("pause");
return 0;
default:
f = 1;
cout << "Please enter a valid choice ";
cout << "between 1, 2, 3, and 4:" << endl;
menu();
cout << "Please enter a choice: ";
cin >> choice;
}
if (f != 1)
{
menu();
cout << "Please enter a choice: ";
cin >> choice;
}
}
system("pause");
return 0;
}