
In C++, how to read a number with decimal in input file and write that decimal number in output file.
for example, in input file, it says
Thomas 3.4
jessica 4.7
what i wrote it
#include
#include
using namespace std;
int main() {
ifstream fin;
ofstream fout;
fin.open("studentdoc.txt");
fout.open("output.txt");
string name1, name2;
float grade1, grade2;
fin>>name1>>grade1>>name2>>grade2;
fout<>grade1>>name2>>grade2;
(close the file)
the output file, always does not show decimal.
it appears as"Thomas3jessica4"
how to fix this? and how to find the average of the grade?
how to give it space in the output file between each name and grade, instead of letting them stick together? how to read the third line string name in an input file(not the one shown above)?
Thank you! this is from a fundenmental course, please don't use complicated/advanced methods etc.

Step by stepSolved in 3 steps with 1 images

- Pointers and references are fully equivalent True Falsearrow_forwardWrite a C++ Program using classes, functions (recursive and otherwise), arrays and other C++ commands to sort a file using Selection Sort. The user will enter the filename. The file should be sorted by the following fields: first by Last Name, then by Mother’s Maiden Name, then by First Name and finally by Second Name (or Initial). The sorted file should be written to file and the first 10 results displayed on screen. Use the following format for both the screen output and the file created: ----------------------------------------------------------------| Last Name | Mother’s Maiden Name | First Name | Second Name | ----------------------------------------------------------------| Saotome | Tendo | Ranma | P | |---------------------------------------------------------------| Son | Kakarot | Goku | A |----------------------------------------------------------------| Yeager | Kaiser | Eren…arrow_forwardUsing C++, create statements that do the following: Define an enum type, birdType, with the values PEACOCK, SPARROW, CANARY, PARROT, PENGUIN, OSTRICH, EAGLE, CARDINAL, and HUMMINGBIRD. Declare a variable bird of the type birdType. Assign CANARY to the variable bird. Advance bird to the next value in the list. Decrement bird to the previous value in the list. Output the value of the variable bird. Input value in the variable bird.arrow_forward
- Please answer in C++arrow_forwardIn the code segment Double radius = 4.5; Const double* ptr = & radius;The ptr is constant, but the data pointed to by the pointer ptr is not constant options: True Falsearrow_forwardIn C++, a pointer variable is a special kind of data storage. Do you know how to put it to use?arrow_forward
- It’s due in C++ Please tell me which code is for StudentMaim.c and which for studentInfo.h and studentInfo.carrow_forwardYou are required to write a program that creates a mini database of HairColor objects..... For this, create a structure HairColor with fields brand – string color - string price - float totalVolume – float currentVolume – float // amount of volume currently available. You need to provide following functions in the struct Provide a function print() so that when called, this function prints the details about the Hair color in formatted manner. IsAvailable(String Technique) which checks the volume of color in the bottle if available for the required technique then returns true otherwise false. isEmpty() this will check whether the bottle is empty or not. You need to provide the function apply (String technique). This function represents the action of applying hair color to hair based on technique user selects Techniques are (highlight, Bronde, Ombre, Sombre) also note down please check that the color is available because volume required for each type of technique is different as for…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





