Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CAN YOU PLEASE SOLVE IT USING C++ LANGUAGE? CAN YOU PLEASE SOLVE IT USING C++ LA

ID: 3762256 • Letter: C

Question

CAN YOU PLEASE SOLVE IT USING C++ LANGUAGE?

CAN YOU PLEASE SOLVE IT USING C++ LANGUAGE?

Write a program that processes the data of a retail company with following requirements: 1. Define a new data type (struct) of Customer, with following members ID, first name, last name, number of items purchased, price of a single item, and total spending. 2. In the main function, declare an array of Customer 3. The array should be created dynamically. In other words, you do not know how many customers when you write the program. The program can asks a user to enter a number, or better yet, let the code to count the number of records in the file. 4. The main function reads the data from a file of "customers.dat. Each row represents a customer's record, with ID, first name, last name, number of item purchased and the price of a single item. The data columns are separated by white spaces 5. 6. Store the customer data in the array. Design a function, computeTotals, to calculate the total spending of each customer: total-numItemsprice. computeTotals takes two parameters, the array and the number of customers computeTotals must be implemented with pointer notation (3-point deduction for using non- pointer notations). In the main function, print out all records, including the total spending, such as: 7. 8. 9. Scott Adams 3 22.86 68.58 1001 1002 NicholasAllen 810.00 80.00

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

typedef struct Customer
{
int ID;
string firstName;
string lastName;
int numberOfItems;
double priceOfItem;
double totalSpendings;
}Customer;

void computeTotals(Customer *customerArray, int numberOfCustomers)
{
for(int i = 0; i < numberOfCustomers; i++)
(customerArray+i)->totalSpendings = (customerArray+i)->priceOfItem * (customerArray+i)->numberOfItems;
}
int main()
{
int numberOfCustomers;
Customer *customerArray;
cout<<"Enter the number of customers: ";
cin>>numberOfCustomers;
customerArray = (Customer *)malloc(sizeof(Customer) * numberOfCustomers);
ifstream ipFile;
ipFile.open("customers.dat");
int count = 0;
while(!ipFile.eof())
{
ipFile>>(customerArray+count)->ID;
ipFile>>(customerArray+count)->firstName;
ipFile>>(customerArray+count)->lastName;
ipFile>>(customerArray+count)->numberOfItems;
ipFile>>(customerArray+count)->priceOfItem;
count++;
}
computeTotals(customerArray, numberOfCustomers);
for(int i = 0; i < numberOfCustomers; i++)
{
cout<<(customerArray+i)->ID<<" ";
cout<<setw(10)<<(customerArray+i)->firstName<<" ";
cout<<(customerArray+i)->lastName<<" ";
cout<<(customerArray+i)->numberOfItems<<" ";
cout<<fixed<<setprecision(2)<<(customerArray+i)->priceOfItem<<" ";
cout<<fixed<<setprecision(2)<<(customerArray+i)->totalSpendings<<endl;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote