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

1.Write a program that accepts as input the mass, in grams, and density, in gram

ID: 668095 • Letter: 1

Question

1.Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places.

Do an analysis and design the algorithm. Implement your design, compile and test it.

2. The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets—box, sideline, premium, and general admission. After each game, data is stored in a flat file in the following form:

ticketPrice numberOfTicketsSold

Sample data are shown below:
250 5750
100 28000
50 35750
25 18750

The first line indicates that the ticket price is $250 and that 5750 tickets were sold at that price. Output the number of tickets sold and the total sale amount. Format your output with two decimal places.

To solve this problem, you must create the input data file manually. To do this in CodeBlocks, go to the File menu and select New and then Empty File. A popup will ask if you want to add this file to the project. When you say yes, you will have to name the file. It is best to put a .txt extension on the file name. This type of file is called a flat file. A flat file is similar to a spread sheet in that all the fields (columns) contain the same type of information and the records (rows) contain different data values.

Perform an analysis and design your algorithm. Implement the design, compile the code and test it.

Explanation / Answer

1.#include<iostream.h>

float main()

{

float mass;

float density;

float volume=0;

cin>>mass>>density;

volume= mass/density;

std::cout << std::setprecision(2) << std::fixed; //to restrict output upto two decimal places.

cout<<volume;

return 0;

}

2.

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>


using namespace std;

int main()
{
double boxPrice, sidelinePrice, premiumPrice, generalPrice;
double box, sideline, premium, general;
double boxTotal, sidelineTotal, premiumTotal, generalTotal, totalTickets, totalDollers, avgPerTicket;
string filename;

ifstream inData;

cout << "please enter the location of the file you wish to input: " << endl;
getline(cin, filename);

inData.open(filename.c_str());

inData >> boxPrice >> box >> sidelinePrice >> sideline >> premiumPrice >> premium >> generalPrice >> general; //extracting data from file.

cout << " box ticket price: $" << boxPrice << ' ' << "box tickets sold: " << box << endl;
cout << "sideline ticket price: $" << sidelinePrice << ' ' << "sideline tickets sold: " << sideline << endl;
cout << "premium ticket price: $" << premiumPrice << ' ' << "premium tickets sold: " << premium << endl;
cout << "general ticket price: $" << generalPrice << ' ' << "general tickets sold: " << general << endl;

boxTotal = (box * boxPrice);
sidelineTotal = (sideline * sidelinePrice);
premiumTotal = (premium * premiumPrice);
generalTotal = (general * generalPrice);
totalTickets = (box + sideline + premium + general);
totalDollers = (boxTotal + sidelineTotal + premiumTotal + generalTotal);
avgPerTicket = (totalDollers / totalTickets);


cout << fixed << showpoint << setprecision(2);
cout << " total $ from box tickets:" << ' ' << "$" << boxTotal << endl;
cout << "total $ from sideline tickets:" << ' ' << "$" << sidelineTotal << endl;
cout << "total $ from premium tickets:" << ' ' << "$" << premiumTotal << endl;
cout << "total $ from general tickets:" << ' ' << "$" << generalTotal << endl;
cout << noshowpoint << setprecision(0);
cout << " total tickets sold:" << ' ' << ' ' << totalTickets << endl;
cout << showpoint << setprecision(2);
cout << "average $ per ticket sold:" << ' ' << "$" << avgPerTicket << endl;
cout << "total $ from all ticket sales:" << ' ' << "$" << totalDollers << endl;

return 0;
}

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