Concept explainers
#include <iostream>
#include<iomanip>
#include<fstream>
#include<sstream>
#include<string.h>
using namespace std;
//Define the main function
int main()
{
//Create the object of fstream class and opening the file
ifstream inpfile("order.txt");
string fline;
double sub_total, tax, shipping=14.95, grand_total, line_total;
double priceA=17.46, priceB=10.13, priceC=2.11, priceD=23.13, priceE=74.56, priceF=1.11, priceG=9.34, priceH=3.45;
cout<<"Thank You! Your order is summarized below: "<<endl;
cout<<"-----------------------------------------------"<<endl;
cout<<"| Product\t|Quantity\t|Line total |"<<endl;
cout<<"-----------------------------------------------"<<endl;
while (getline(inpfile, fline)) {
istringstream ists(fline);
string product;
int quantity;
if (!(ists >>product>> quantity)) {
break;
}
else{
if(product=="A")
line_total=quantity*priceA;
else if (product=="B")
line_total=quantity*priceB;
else if (product=="C")
line_total=quantity*priceC;
else if (product=="D")
line_total=quantity*priceD;
else if (product=="E")
line_total=quantity*priceE;
else if (product=="F")
line_total=quantity*priceF;
else if (product=="G")
line_total=quantity*priceG;
else if (product=="H")
line_total=quantity*priceH;
cout<<"| "<<setw(2)<<product<<"\t\t| "<<setw(2)<<quantity <<"\t\t| "<<fixed<<setprecision(2)<<setw(10)<<line_total<<setw(2)<<" |"<<endl;
cout<<"-----------------------------------------------"<<endl;
sub_total=sub_total+line_total;
}
tax=sub_total*0.17;
grand_total=sub_total+tax+shipping;
}
cout<<"| "<<setw(2)<<"Sub_total"<<"\t| "<<setw(2)<<" " <<"\t\t| "<<fixed<<setprecision(2)<<setw(10)<<sub_total<<setw(2)<<" |"<<endl;
cout<<"-----------------------------------------------"<<endl;
cout<<"| "<<setw(2)<<"Tax"<<"\t\t| "<<setw(2)<<" " <<"\t\t| "<<fixed<<setprecision(2)<<setw(10)<<tax<<setw(2)<<" |"<<endl;
cout<<"-----------------------------------------------"<<endl;
cout<<"| "<<setw(2)<<"Shipping"<<"\t| "<<setw(2)<<" " <<"\t\t| "<<fixed<<setprecision(2)<<setw(10)<<shipping<<setw(2)<<" |"<<endl;
cout<<"-----------------------------------------------"<<endl;
cout<<"| "<<setw(2)<<"Grand Total"<<"\t| "<<setw(2)<<" " <<"\t\t| "<<fixed<<setprecision(2)<<setw(10)<<grand_total<<setw(2)<<" |"<<endl;
cout<<"-----------------------------------------------"<<endl;
inpfile.close();
return 0;
}
Programming Assignment 2
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
float lowerTemp,higherTemp,increment;
cout<<"Please Enter the lower value for the conversion table (Celsius)";
cin>> lowerTemp;
cout<<"Please Enter the higher value for the conversion table (Celsius)";
cin>> higherTemp;
//input validation
if(lowerTemp > higherTemp){
cout<<"lower value should not greater that higher value";
return 1;
}
cout<<"what do you want to use for incremented value";
cin>> increment;
if(increment <= 0){
cout<<"The increament value should be greater than 0.";
return 1;
}
ofstream write_data;
write_data.open("conversion_table.txt");
if(!write_data) { //error
cerr << "Error in opening the file." << endl;
exit(1);
}
//print heading
write_data << "C \t F \t N" <<endl;
//compute temp equivalent
//save data into the file
while (lowerTemp <= higherTemp){
float f = (9/5) * lowerTemp + 32;
float n = 0.33 * lowerTemp;
write_data << fixed << setprecision(2) <<lowerTemp << "\t" <<
setprecision(2) << f << "\t" << setprecision(2) << n <<endl;
lowerTemp += increment;
}
cout<<"\nData is saved in the file.";
write_data.close();
return 0;
}
Question-
-
- Address any questions or misconceptions the reviewer may have posted. (I like your program! I don't see very many things to nitpick at. Perhaps, instead of using "cout << "---------------" << endl;" you could use something along the lines of "cout << setw(10) << setfill('-') << "-" << endl;" in case you wanted to change that part or prevent changes to how it looks on different screens. Good job on the comments and everything.)
- Indicate how useful the feedback was.
- Did you understand the comments/observations/suggestions?
- Did the review point out flaws/shortcomings in your program?
- Did you learn anything from the critique?
- Did the process help you better understand the original programming assignment? would you modify your program based on the feedback/observations?
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images
- 10. When using a std::vector, what values do we expect to get from the size and empty member functions after calling the clear member function? Complete the table below with the expected values. member function value after donations.clear() donations.size() donations.empty()arrow_forwardint cal_media() {cout<<"Enter Your Name"<<endl;cin>>name;cout<<"Enter the Both subject marks"<<endl;cin>>marks1>>marks2;totalmarks = marks1 + marks2;} Question 4: On above code overload unary operator prefix decrement and post fix increment forthe calc-media() function.arrow_forwardineering Computer Engineering Q&A Library Function: Create a function which accepts patient id and display the patients name, date admitted. Sample output is: The patient name is Maryam, she got admitted on 12-Feb-2020 Function: Create a function which accepts patient id and display the patients name, date admitted. Sample output is: The patient name is Maryam, she got admitted on 12-Feb-2020 Question Function: Create a function which accepts patient id and display the patients name, date admitted. Sample output is: The patient name is Maryam, she got admitted on 12-Feb-2020 Procedure Write a Procedure that accepts patient id and display the patient id, name, test name and result. Package Create a package which contains the above created procedure in the specification. Create package body of the above given procedure. And finally call the procedure created above by passing the patient id then display the output as shown below: Sample output: Patient id is: P0232…arrow_forward
- C++ help with this fixing code .cpp file #include<iostream>#include<string>#include<vector>#include"Food.h"using namespace std; class Nutrition{ private: string name; double Calories double Fat double Sugars double Protein double Sodium Nutrition(string n, double c, double f, double s, double p, double S): name(n), Calories(c), Fat(f),Sugars(s), Protein(p),Sodium(S){} food[Calories]= food[Fat]=food[Sugars]=food[Protein]=food[Sodium]=0; name = "";} Nutrition(string type, double calories, double fat, double sugar,double protein, double sodium){ food[Calories]= calories; food[Fat]=fat; food[Sugars]= sugar; food[Protein]=protein; food[Sodium]=sodium; name= type; } void setName(string type){ name = type; } void setCalories(double calories){ food [Calories]= calories; } void setFat(double fat){ food [Fat]= fat; } void setSugars(double sugar){ food [Sugars]= sugar; } void setProtein(double protein){ food [Protein]= protein; } void…arrow_forwardC++ formatting please Write a program (not a function) that reads from a file named "data.csv". This file consists of a list of countries and gold medals they have won in various Olympic events. Write to standard out, the top 5 countries with the most gold medals. You can assume there will be no ties. Expected Output: 1: United States with 1022 gold medals 2: Soviet Union with 440 gold medals 3: Germany with 275 gold medals 4: Great Britain with 263 gold medals 5: China with 227 gold medalsarrow_forwardFor a local variable in a function to retain its value between calls to the function, it must be declared with the _____________storage-class specifier.arrow_forward
- Programming tracing C language Please help it is tracing on c programming kindly input the visual tracing like line where the process start or error Trace the following program: #include<stdio.h>#include<conio.h>void kar1(char *a, char *b, char *c){*a = 'c'; *b='a'; *c ='b';printf("%c %c %c\n", *a, *b, *c);}main(){char a = 'c', b = 'b', c = 'a';clrscr();printf("%c %c %c\n", a, b, c);kar1(&a,&b,&c);printf("%c %c %c\n", a, b, c);kar1(&c,&b,&a);printf("%c %c %c\n", a, b, c);kar1(&b,&a,&c);printf("%c %c %c\n", a, b, c);getch();return 0;}arrow_forwardstruct employee{int ID;char name[30];int age;float salary;}; (A) Using the given structure, Help me with a C program that asks for ten employees’ name, ID, age and salary from the user. Then, it writes the data in a file named out.txt (B) For the same structure, read the contents of the file out.txt and print the name of the highest salaried employee and youngest employee names name in the outputscreen.arrow_forwardC++ Write Family tree - Build a data structure to store information about father, mother and children. Note that a person can have children with more than one person.You will then need to write a function, which takes two person and tell their relationship. The output can be one of the following: father, mother, and grandfather/mother. · The C++ program should have 1. Structure 2. Function 3. Loop 4. Arrayarrow_forward
- # # FUNCTION strlen(String value) # Argument $a0 = value # returns result in $v0 strlen: li $v0, 0 next: lb $t1, 0($a0) beqz St1, addi Sa0, Sa0, 1 j next strlen_ret: jr SVO, SVO, 1arrow_forwardC++ Golf Course HandicapProgramming Task In this exercise, you will be working with golf handicaps and golf course data. We have provided a golfer's handicap. The information is stored in a text file called golfer.txt inside of the data/ folder. The format of the file is as follows: Lines 1: golfer's handicapWe have also provided some data for a golf course. The information is stored in a text file called course.txt inside of the data/ folder. The format of the file is as follows: Lines 1: course ratingLines 2: slope ratingLines 3: course par Your goal is to create a utility which takes a golfer's handicap, course rating, slope rating, and course par, as standard input (keyboard), and prints the golfer's course handicap. The golfer's course handicap should be expressed as a floating point number. Recall that a golfer's course handicap, is a numerical value that represents the number of strokes a golfer should receive or give when playing a specific golf course. It is used to adjust a…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education