Intro C++ questions:
Question 1:
Assume #include <fstream>
Given
ifstream fpIn;
Write a statement to open a file called carpools.txt and assign the pointer to fpIn. If the file cannot be found, then print out the message No such file and exit the execution of the program.
Question 2:
Meridian Corporation of Fremont is trying to decide whether to reward employees who carpool to work. The proposed plan is to pay each employee in the carpool $ 0.08 per mile if the minimum passenger efficiency of 25.0 is met. The passenger efficiency is calculated as
P =
nm
G
where n is the number of people in the carpool, m is the distance traveled in miles and G is the number of gallons of fuel used.
The file opened in Question 1 (do not open it again but do have a reference to it as a parameter) contains data on existing carpools. The input file represents each existing carpool as a line of data containing the number of people in the carpool, the total commuting distance for a five-day work week, and the number of gallons used. Write a function called calcEfficiency to process this file until the end of data. Calculate the passenger efficiency for each carpool and if the efficiency is greater than 25.0 then output the passenger efficiency and the amount to be rewarded to the screen. Assume the function declaration: Use no arrays! Paste in only the function definition - not main() even it you wrote it to test your program.
Sample carpool.txt
2 80 4
3 125 10.5
2 350
15.9
Sample output Screen:
Efficiency
Money
40.0
$ 6.40
35.7
$10.0044.0
Please help!!
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Intro C++ questions: Question 1: Assume #include <fstream> Given ifstream fpIn; Write a statement to...
QUESTION 6 To determine whether a file was opened successfully, the program can use the fstream function: Hint: google fail() open() close() eof() 10 points QUESTION 7 Which of the following are correct ways to end a loop using a test for end-of-file? (Two correct answers) inStream.get(next); while(!inStream.eof( )) { cout << next; inStream.get(next); } while(inStream->next) { cout << next; } inStream.get(next) while(!eof(inStream)) { cout << next; inStream.get(next); } while(inStream >> next) cout << next; 10 points QUESTION...
How would answer question #4 of this ?
#1 and 2
#include<iostream>
#include <fstream>
using namespace std;
void read(int arr[])
{
string line;
ifstream myfile("input.txt");
int i = 0;
if (myfile.is_open())
{
while (getline(myfile, line))
{
arr[i];
i++;
}
myfile.close();
}
}
void output(int arr[])
{
ofstream myfile("output.txt");
if (myfile.is_open())
{
int i = 0;...
Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...
Write a program in c++ that generates a 100 random numbers between 1 and 1000 and writes them to a data file called "randNum.dat". Then re-open the file, read the 100 numbers, print them to the screen, and find and print the minimum and maximum values. Specifications: If your output or input file fails to open correctly, print an error message that either states: Output file failed to open Input file failed to open depending on whether the output or...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...
Code in C++: Please help me fix the error in function: void write_account(); //function to write record in binary file (NOTE: I able to store data to a txt file but however the data get error when I try to add on data the second time) void display_all(); //function to display all account details (NOTE: This function is to display all the info that save account.txt which is ID, Name, and Type) void modify_account(int); //function to modify record of file...
For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....
absolute C++
QUESTION 1 Which statement is incorrect? When an event occurs that cannot be managed locally, an exception may be thrown. Throwing the exception object transfers control and information gleaned locally to some calling program unit that manages the event, or the program terminates If an exception is thrown in a function, sayf, but not handled there, the exception is propagated to the function that called fo In C++, an exception object can be a user-defined type or any...
write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and remains open until the...
Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...