SlideShare a Scribd company logo
1 of 2
Download to read offline
2. Formatting Output to Files
Solution
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int num;
float root;
ifstream in_stream;
ofstream out_stream;
in_stream.open("Lab9B.in");
if(in_stream.fail())
{
cout << "ERROR: Unable to open file: Lab9B.in" << endl;
exit(EXIT_FAILURE);
}
out_stream.open("Lab9B.out");
if(out_stream.fail())
{
cout << "ERROR: Unable to open file: Lab9B.out" << endl;
exit(EXIT_FAILURE);
}
while(in_stream >> num)
{
root = sqrt(num);
out_stream << std::left;
out_stream << setprecision(5);
out_stream << setw(15);
out_stream << root << endl;
}
in_stream.close();
out_stream.close();
return 0;
}

More Related Content

More from Dhanrajsolanki2091

JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdfJUST DO QUESTION 32) You have discussed with the human resource ma.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdfDhanrajsolanki2091
 
Ins struction Use the information that is associated with your name .pdf
Ins struction Use the information that is associated with your name .pdfIns struction Use the information that is associated with your name .pdf
Ins struction Use the information that is associated with your name .pdfDhanrajsolanki2091
 
I how does double fertilization aid in the survival of land plants o.pdf
I how does double fertilization aid in the survival of land plants o.pdfI how does double fertilization aid in the survival of land plants o.pdf
I how does double fertilization aid in the survival of land plants o.pdfDhanrajsolanki2091
 
how does malpractice affect quality of healthcare service What are .pdf
how does malpractice affect quality of healthcare service What are .pdfhow does malpractice affect quality of healthcare service What are .pdf
how does malpractice affect quality of healthcare service What are .pdfDhanrajsolanki2091
 
How can critical researchers claim to represent groups to which they.pdf
How can critical researchers claim to represent groups to which they.pdfHow can critical researchers claim to represent groups to which they.pdf
How can critical researchers claim to represent groups to which they.pdfDhanrajsolanki2091
 
Discuss Allport’s concept of psychological healthy personality.Des.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdfDiscuss Allport’s concept of psychological healthy personality.Des.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdfDhanrajsolanki2091
 
Earning revenue journal entry is recorded asA Increases assets.pdf
Earning revenue journal entry is recorded asA Increases assets.pdfEarning revenue journal entry is recorded asA Increases assets.pdf
Earning revenue journal entry is recorded asA Increases assets.pdfDhanrajsolanki2091
 
Discuss why is it important to use logical and physical data flow di.pdf
Discuss why is it important to use logical and physical data flow di.pdfDiscuss why is it important to use logical and physical data flow di.pdf
Discuss why is it important to use logical and physical data flow di.pdfDhanrajsolanki2091
 
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdfDid HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdfDhanrajsolanki2091
 
Define each of the following terms. Be clear whether it is at develop.pdf
Define each of the following terms. Be clear whether it is at develop.pdfDefine each of the following terms. Be clear whether it is at develop.pdf
Define each of the following terms. Be clear whether it is at develop.pdfDhanrajsolanki2091
 
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdfCould anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdfDhanrajsolanki2091
 
Complete the following code by deallocating the memory. Int ptr1; .pdf
Complete the following code by deallocating the memory.  Int ptr1;  .pdfComplete the following code by deallocating the memory.  Int ptr1;  .pdf
Complete the following code by deallocating the memory. Int ptr1; .pdfDhanrajsolanki2091
 
Briefly discuss why you are proud to be a mammal and give examples of.pdf
Briefly discuss why you are proud to be a mammal and give examples of.pdfBriefly discuss why you are proud to be a mammal and give examples of.pdf
Briefly discuss why you are proud to be a mammal and give examples of.pdfDhanrajsolanki2091
 
AVR data memory consists of (Flash ROM, internal SRAM). True or false.pdf
AVR data memory consists of (Flash ROM, internal SRAM). True or false.pdfAVR data memory consists of (Flash ROM, internal SRAM). True or false.pdf
AVR data memory consists of (Flash ROM, internal SRAM). True or false.pdfDhanrajsolanki2091
 
Below is a table of probabilities representing a sample survey of 100.pdf
Below is a table of probabilities representing a sample survey of 100.pdfBelow is a table of probabilities representing a sample survey of 100.pdf
Below is a table of probabilities representing a sample survey of 100.pdfDhanrajsolanki2091
 
Based on the Spectroscopy data below, identify the material and it.pdf
Based on the Spectroscopy data below, identify the material and it.pdfBased on the Spectroscopy data below, identify the material and it.pdf
Based on the Spectroscopy data below, identify the material and it.pdfDhanrajsolanki2091
 
Attached is case study of how Whirlpool and Lowes collaborated to .pdf
Attached is case study of how Whirlpool and Lowes collaborated to .pdfAttached is case study of how Whirlpool and Lowes collaborated to .pdf
Attached is case study of how Whirlpool and Lowes collaborated to .pdfDhanrajsolanki2091
 
7. Winter is here. I hope you have enough of the right fatty acids o.pdf
7. Winter is here. I hope you have enough of the right fatty acids o.pdf7. Winter is here. I hope you have enough of the right fatty acids o.pdf
7. Winter is here. I hope you have enough of the right fatty acids o.pdfDhanrajsolanki2091
 
1. What effect does pulmonary edema have on blood oxygenation2. W.pdf
1. What effect does pulmonary edema have on blood oxygenation2. W.pdf1. What effect does pulmonary edema have on blood oxygenation2. W.pdf
1. What effect does pulmonary edema have on blood oxygenation2. W.pdfDhanrajsolanki2091
 
Write a static method named numberoddSum that accepts a positive inte.pdf
Write a static method named numberoddSum that accepts a positive inte.pdfWrite a static method named numberoddSum that accepts a positive inte.pdf
Write a static method named numberoddSum that accepts a positive inte.pdfDhanrajsolanki2091
 

More from Dhanrajsolanki2091 (20)

JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdfJUST DO QUESTION 32) You have discussed with the human resource ma.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
 
Ins struction Use the information that is associated with your name .pdf
Ins struction Use the information that is associated with your name .pdfIns struction Use the information that is associated with your name .pdf
Ins struction Use the information that is associated with your name .pdf
 
I how does double fertilization aid in the survival of land plants o.pdf
I how does double fertilization aid in the survival of land plants o.pdfI how does double fertilization aid in the survival of land plants o.pdf
I how does double fertilization aid in the survival of land plants o.pdf
 
how does malpractice affect quality of healthcare service What are .pdf
how does malpractice affect quality of healthcare service What are .pdfhow does malpractice affect quality of healthcare service What are .pdf
how does malpractice affect quality of healthcare service What are .pdf
 
How can critical researchers claim to represent groups to which they.pdf
How can critical researchers claim to represent groups to which they.pdfHow can critical researchers claim to represent groups to which they.pdf
How can critical researchers claim to represent groups to which they.pdf
 
Discuss Allport’s concept of psychological healthy personality.Des.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdfDiscuss Allport’s concept of psychological healthy personality.Des.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdf
 
Earning revenue journal entry is recorded asA Increases assets.pdf
Earning revenue journal entry is recorded asA Increases assets.pdfEarning revenue journal entry is recorded asA Increases assets.pdf
Earning revenue journal entry is recorded asA Increases assets.pdf
 
Discuss why is it important to use logical and physical data flow di.pdf
Discuss why is it important to use logical and physical data flow di.pdfDiscuss why is it important to use logical and physical data flow di.pdf
Discuss why is it important to use logical and physical data flow di.pdf
 
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdfDid HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
 
Define each of the following terms. Be clear whether it is at develop.pdf
Define each of the following terms. Be clear whether it is at develop.pdfDefine each of the following terms. Be clear whether it is at develop.pdf
Define each of the following terms. Be clear whether it is at develop.pdf
 
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdfCould anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
 
Complete the following code by deallocating the memory. Int ptr1; .pdf
Complete the following code by deallocating the memory.  Int ptr1;  .pdfComplete the following code by deallocating the memory.  Int ptr1;  .pdf
Complete the following code by deallocating the memory. Int ptr1; .pdf
 
Briefly discuss why you are proud to be a mammal and give examples of.pdf
Briefly discuss why you are proud to be a mammal and give examples of.pdfBriefly discuss why you are proud to be a mammal and give examples of.pdf
Briefly discuss why you are proud to be a mammal and give examples of.pdf
 
AVR data memory consists of (Flash ROM, internal SRAM). True or false.pdf
AVR data memory consists of (Flash ROM, internal SRAM). True or false.pdfAVR data memory consists of (Flash ROM, internal SRAM). True or false.pdf
AVR data memory consists of (Flash ROM, internal SRAM). True or false.pdf
 
Below is a table of probabilities representing a sample survey of 100.pdf
Below is a table of probabilities representing a sample survey of 100.pdfBelow is a table of probabilities representing a sample survey of 100.pdf
Below is a table of probabilities representing a sample survey of 100.pdf
 
Based on the Spectroscopy data below, identify the material and it.pdf
Based on the Spectroscopy data below, identify the material and it.pdfBased on the Spectroscopy data below, identify the material and it.pdf
Based on the Spectroscopy data below, identify the material and it.pdf
 
Attached is case study of how Whirlpool and Lowes collaborated to .pdf
Attached is case study of how Whirlpool and Lowes collaborated to .pdfAttached is case study of how Whirlpool and Lowes collaborated to .pdf
Attached is case study of how Whirlpool and Lowes collaborated to .pdf
 
7. Winter is here. I hope you have enough of the right fatty acids o.pdf
7. Winter is here. I hope you have enough of the right fatty acids o.pdf7. Winter is here. I hope you have enough of the right fatty acids o.pdf
7. Winter is here. I hope you have enough of the right fatty acids o.pdf
 
1. What effect does pulmonary edema have on blood oxygenation2. W.pdf
1. What effect does pulmonary edema have on blood oxygenation2. W.pdf1. What effect does pulmonary edema have on blood oxygenation2. W.pdf
1. What effect does pulmonary edema have on blood oxygenation2. W.pdf
 
Write a static method named numberoddSum that accepts a positive inte.pdf
Write a static method named numberoddSum that accepts a positive inte.pdfWrite a static method named numberoddSum that accepts a positive inte.pdf
Write a static method named numberoddSum that accepts a positive inte.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsPallavi Parmar
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfKartik Tiwari
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of PlayPooky Knightsmith
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfElizabeth Walsh
 

Recently uploaded (20)

Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell Tolls
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
 

2. Formatting Output to FilesSolution#includeiostream #inc.pdf

  • 1. 2. Formatting Output to Files Solution #include #include #include #include #include using namespace std; int main() { int num; float root; ifstream in_stream; ofstream out_stream; in_stream.open("Lab9B.in"); if(in_stream.fail()) { cout << "ERROR: Unable to open file: Lab9B.in" << endl; exit(EXIT_FAILURE); } out_stream.open("Lab9B.out"); if(out_stream.fail()) { cout << "ERROR: Unable to open file: Lab9B.out" << endl; exit(EXIT_FAILURE); } while(in_stream >> num) { root = sqrt(num); out_stream << std::left;
  • 2. out_stream << setprecision(5); out_stream << setw(15); out_stream << root << endl; } in_stream.close(); out_stream.close(); return 0; }