Looking for some assistance with C++ code using visual studio for the following:
Input file:
Field |
Size |
Comments |
Trip Number |
5 digits |
Integers Only |
Passenger count |
1 digit integer |
This is not a clown cab… you can't fit 10 people in. ? |
Distance |
999.99 |
The distance of the trip. |
Fare Amount |
999.99 |
The base fare amount |
Toll Amount |
999.99 |
The toll if any for this trip. |
For example, the file small.txt looks like:
98002 3 17.7 52.5 5.25
10839 1 2.4 10 0
77087 2 1.2 5.5 0
9132 1 21.7 58 7.87
51535 3 1.1 8.5 0
5015 2 1 7 0
There will be at most 50 records in this file.
Logic
File Name Input: You must make your program flexible and ask the user the name of the file.
For each line you will calculate:
Totals
At the end of the report there are some statistics. There are lots of ways we could do this, and I want you to practice using arrays, so for this lab you will have an array of doubles to store the total fares, one for each line in the file. You can track the total number of people with a single integer.
Then, to create the statistics, you will have a function that takes your array of total fares and your integer for the total number of people. It will output to the screen the following:
Total People Transported - The integer that you pass in.
Total Paid – The Grand total of all the total fares. You will loop through your array and sum the values.
Average Cost Per Person – Your Total Paid divided by your Total People transported.
/* C++ program that prompt user to enter the name of
the file to read data. The find the cost per file, then total
people transported , total paid amount on console output
*/
//main.cpp
//include header files
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
//function prototype
int totalTransported(int people[],int size);
double totalPaid(double fares[], int size);
//start of main funciton
int main()
{
//declare arrays to read 50 records from file
const int size=50;
int tripNum[size];
int passengerCount[size];
double distance[size];
double fare[size];
double tollfee[size];
int index=0;
double totalfare=0;
double costPerMile=0;
string fileName;
//read file name
cout<<"Enter name of file to read : ";
getline(cin,fileName);
//Open file object
ifstream fin;
fin.open(fileName);
if(!fin)
{
cout<<fileName<<" file
is not found."<<endl;
system("pause");
return EXIT_FAILURE;
}
//read data from file
while(index<size && !fin.eof())
{
fin>>tripNum[index];
fin>>passengerCount[index];
fin>>distance[index];
fin>>fare[index];
fin>>tollfee[index];
//calculate cost per
mile
if(distance[index]==0)
costPerMile=0;
else
costPerMile=(fare[index]+tollfee[index])/distance[index];
cout<<fixed<<left<<"For line
"<<index+1<<", Cost per Mile,$:"
<<setw(10)<<setprecision(2)<<costPerMile<<endl;
index++;
}
fin.close();
int count=index;
int
totalPassengers=totalTransported(passengerCount,count);
//print the total passengers
cout<<"Number of passengers transported :
"<<totalPassengers<<endl;
double
totalPaidAmount=totalPaid(fare,count);
//print the total paid
cout<<"Total paid,$ :
"<<totalPaidAmount<<endl;
//Print the average cost per person
cout<<fixed<<setw(30)<<"Average Cost
Per Person,$ :"<<setprecision(2)<<
totalPaidAmount/totalPassengers<<endl;
system("pause");
return 0;
}
/*
The function, totalTransported that takes an integer array and
size
as arguments and then calculate the total number of persons
transported
*/
int totalTransported(int people[],int size)
{
int index=0;
int totalPassengers=0;
while(index<size)
{
totalPassengers=totalPassengers+people[index];
index=index+1;
}
return totalPassengers;
}
/*
The function, totalPaid that takes an double fare array and
size
as arguments and then calculate the total paid amount
*/
double totalPaid(double fares[], int size)
{
int index=0;
float totalPaid=0;
while(index<size)
{
totalPaid=totalPaid+fares[index];
index=index+1;
}
return totalPaid;
}
small.txt
98002 3 17.7 52.5 5.25
10839 1 2.4 10 0
77087 2 1.2 5.5 0
9132 1 21.7 58 7.87
51535 3 1.1 8.5 0
5015 2 1 7 0
sample output:
Looking for some assistance with C++ code using visual studio for the following: Input file: Field...
C++ code The assignment has two input files: • LSStandard.txt • LSTest.txt The LSStandard.txt file contains integer values against which we are searching. There will be no more than 100 of these. The LSTest.txt file contains a set of numbers that we are trying to locate within the standard data set. There will be no more than 50 of these. Read both files into two separate arrays. Your program should then close both input files. All subsequent processing will be...
USE C++ FOR THE CODE THAT CAN RUN IN VISUAL STUDIO 2019
(or a complier)
Ignore the last paragraph on the bottom of the
page!
\
Write a program YourName-Assignments (replace Your Name with your actual name, no spaces) that reads from students' records (one student per line) in the following format: Last Name Tests Grade Assignments Grade and computes and outputs (to the console) the STUDENT STATISTICS in a table format one line per student: Student Name Total Points...
This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...
Write a C program as follows: Single source code file Requests the user to input two integer numbers Requests the user to make a choice between 0 (add), 1 (subtract), or 2 (multiply) Declares three separate functions Uses a pointer to these three functions to perform the requested action Outputs the result to the screen Submit your program source code file to this assignment. Sample Output Enter first integer number: 15 Enter second integer number: 10 Enter Choice: 0 for...
Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...
write a code on .C file
Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...
C++ Objective: Write a program to read a pre-specified file containing salespersons' names and daily sales for some number of weeks. It will create an output file with a file name you have gotten from the user that will hold a summary of sales data. Specifications: 1. You should do a functional decomposition to identify the functions that you will use in the program. These should include reading and writing the files, tallying and showing statistics, etc. 2. The program...
Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...
Question2 uses structured design implemented in C. Array of records (structs) with file I/O is needed. The program takes two inputs at a time. The name of a person, and, the coin value as an integer in the range 5 to 95. Input coin values should always be divisible by 5 (integer division). Names are one word strings. An example input is: Jane 30 This input line indicates that 30 cents change is to be given to Jane. Output change...
how to add methods into thjs code using C# on visual
studio?
-validatetextbox should return a true false depending if input
is valid
-resetinput should clear all input and restart radiobuttons to
the defult positions
-displaymessge must display messge box to the user displaying
such as “5+8=12”
calculator.cs x Prearam S Miscellaneous Files ator.Designer.c s Calculato 1 曰using Systemi 2 using System.Collections.Generic; using System.ComponentModel; 4 using System.Data; s using System.Drawing; 6 using System.Linq 7using System.Text; 8 using System.Threading.Tasks; 9 using...