Prompt the user to input the following user information, and echo the informatio
ID: 3789179 • Letter: P
Question
Prompt the user to input the following user information, and echo the information to the screen.
1. Full User Name - a string that may contain blanks ex: Jean Morton
2. User Alias – a string that does not contain blanks ex: potteryQueenJean
3. Gender – a single character ex: f
.4. Rating – a floating point value ex: 93.36
5. UID (User ID number) – an integer value ex: 902514
6. Phone Number – a string that does not contain blanks ex: 7575551212
Prompt the user for the name of the file containing the list of items for auction: Open the file and process the following for each item in the file:.
1. Name – a string that may contain blanks ex: “Chinese Vase with Green Elephant decor”
2. Time – a string that does not contain blanks ex: 07:10:36
3. Price – a floating point value. ex: 38.99
Determine and display the following information:
1. Total Number of all items up for auction – an integer value
2. Highest and Lowest Cost found amongst these items – floating point values.
3. Average Cost of all items – floating point value. (price sum / number items )
4. Rounded Average Cost of all items – an integer value. (round average found above )
5. WebAddPoints – floating point value(calc with formula below)
webpoints=number of items +(sqrt(average price)/(donation+webadd))^3
1.WebAddPoints is a value calculated with the formula above, and using DONATION and WEBADD which are constant values declared in the provided code template.
2. You must use the math functions pow and sqrt for the above formula.
3. If there is only one item in the items file, then the WebAddPoints is equal to zero
INPUT FILE:
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
const float DONATION = 0.18;
const int WEBADD = 25;
int main()
{
cout << "PROJECT 1: Programmer Name & Info Here ";
//------------------------------------------------------------
/// Part A: Gather and Store User Information
//variable declarations
string userName, alias, sex, ID, phone, rate, file_name;
//Prompt for the user info
cout<<" _________________________________ ";
cout<<"Enter full name:";
getline(cin,userName);
cout<<"Enter alias : ";
getline(cin,alias);
cout<< "Enter your Gender :";
getline(cin,sex);
cout << "Enter user ID : ";
getline (cin,ID);
cout<<"Enter seven digit phone :";
getline(cin,phone);
cout << "Enter User Rating : ";
getline (cin,rate);
// full name
///--------------------------------------------
//------------INPUT FILE STREAM SETUP---------
///-----------------------------------------------
//------------OUTPUT FILE STREAM SETUP-----------
///-----------------------------------------------
//---DISPLAY USER INFORMATION (to file and screen)
cout<<"________User Information_________";
cout<<" Name : "<<userName;<<username;
//setup for formatiing for output
//Part B: process the list of for auction
//variable for auction items
// read line 1, containning no of items in the file
//read data describing 1 item
cout<<" ______item listing_______";
cout<<" Price Time Name ';
//begin and end of loop that processes data
// calculate web-add-points
//determine rounded integer value of average
//determine rounded integer value of donation amount
//output result
cout<<fixed<<showpoint<<setprecision(2);
cout<<"_________________":
cout<<' _______Item statistics_______";
//end of more than one item
//or else we just had one//end of else we just had one
cout<<" ";
return 0;
}
SAMPLE OUTPUT
PROJECT 1 Programmer Name & Info Here name Lucy S nter Enter alias lucyd Enter Gender: f 83943 Enter user ID Enter seven digit phone 8005551212 91.53 Enter user Rating Enter items file name items 4.txt User Informati Name Lucy Skkydyme Alias lucyd Sex ID 83943 Phone 8005551212 91.53 Rate tem Listin Price Time Name 23.00 05:08:23 case 68.00 09:16:12 Stationary products 9968.99 13:24:32 3-D Bio-printer 1899 Colt Revolver 6801.99 20:30:48 Set of books 452.99 09:25:34 822.69 11:47: 16 Pickled Dinosaur Egg tem Statistics Item Count Avg Price 3023.00 Donation 544.00 High Price: 9968.99 Low Price 23.00 WebAddPts 1321.41 Process returned 0 COx0) execution time 106.830Explanation / Answer
C++ code:
#include <bits/stdc++.h>
using namespace std;
const float DONATION = 0.18;
const int WEBADD = 25;
int main()
{
string name, Alias, Gender, Age,Rating, UID,PhoneNumber;
cout <<"Please enter Full User Name! "<< endl;
std::getline (std::cin,name);
cout <<"Please enter User Alias! "<< endl;
// getline(Alias);
std::getline (std::cin,Alias);
cout <<"Please enter Gender! "<< endl;
// cin >> Gender;
std::getline (std::cin,Gender);
cout <<"Please enter Age! "<< endl;
// cin >> Age;
std::getline (std::cin,Age);
cout <<"Please enter Rating! "<< endl;
// cin >> Rating;
std::getline (std::cin,Rating);
cout <<"Please enter UID! "<< endl;
// cin >> UID;
std::getline (std::cin,UID);
cout <<"Please enter Phone Number! "<< endl;
// cin >> PhoneNumber;
std::getline (std::cin,PhoneNumber);
cout << "Please enter filename" << endl;
string filename;
std::getline (std::cin,filename);
string line;
int entries = 0;
float high = std::numeric_limits<float>::min();
float low = std::numeric_limits<float>::max();
std::vector<int> prices;
ifstream myfile (filename.c_str());
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
entries++;
string buf; // Have a buffer string
stringstream ss(line); // Insert the string into a stream
vector<string> tokens; // Create vector to hold our words
while (ss >> buf)
tokens.push_back(buf);
float p = atof(tokens[0].c_str() ) ;
if(high < p)
{
high = p;
}
if(low > p)
{
low = p;
}
prices.push_back(p);
}
myfile.close();
}
else
{
cout << "Unable to open file" << endl;
exit(1);
}
int itemcount = prices.size();
int average = 0;
for (int i = 0; i < prices.size(); ++i)
{
average = average + prices[i];
}
average = average/prices.size();
float WebAddPoints = itemcount +pow((sqrt(average)/(DONATION+WEBADD)),3);
if(itemcount == 1)
{
WebAddPoints = 0;
}
cout << "--------------User Information!----------" << endl;
cout << "Name " << name<< endl;
cout << "Alias " << Alias << endl;
cout << "Sex " << Gender << endl;
cout << "Age " << Age << endl;
cout << "ID " << UID << endl;
cout << "Phone " << PhoneNumber << endl;
cout << "Rate " << Rating << endl;
cout << "--------------Item Statistics!----------" << endl;
cout << "Item Count " << itemcount << endl;
cout << "Average Price " << average << endl;
cout << "DONATION " << DONATION << endl;
cout << "High Price " << high << endl;
cout << "Low Price " << low << endl;
cout << "WebAddPoints " << WebAddPoints << endl;
return 0;
}
data.txt
23.00 01:02:03 name1
68.00 01:02:03 name2
9968.99 01:02:03 name3
6801.99 01:02:03 name4
452.99 01:02:03 name5
822.99 01:02:03 name6
Sample Output:
Please enter Full User Name!
lucy skkdyme
Please enter User Alias!
lucyd
Please enter Gender!
f
Please enter Age!
15
Please enter Rating!
8
Please enter UID!
1234
Please enter Phone Number!
9812321234
Please enter filename
data.txt
--------------User Information!----------
Name lucy skkdyme
Alias lucyd
Sex f
Age 15
ID 1234
Phone 9812321234
Rate 8
--------------Item Statistics!----------
Item Count 6
Average Price 3022
DONATION 0.18
High Price 9968.99
Low Price 23
WebAddPoints 16.4058
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.