SlideShare a Scribd company logo
1 of 4
Download to read offline
num.txt(Save this file under D Drive.Then the path of the file is D: um.txt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
CPP Code
#include
#include
using namespace std;
//Declaring Global variable
int sum=0;
//Function declarations
void readFromFile();
void writeToFile();
/* Function implementation which will
* read the numbers from the file and calculates the sum of
* the numbers which are multiples of 2 or 5
*/
void readFromFile()
{
int number,sum=0;
//fileInput reference
ifstream dataIn;
//Opening input file
dataIn.open("D: um.txt");
while(dataIn>>number)
{
if(number%2==0 || number%5==0)
{
sum+=number;
}
}
//closing the input stream
dataIn.close();
}
/* Function implementation which will
* display the sum into another text file
*/
void writeToFile()
{
//fileoutput reference
ofstream myfile;
//Opening the file
myfile.open ("D: um1.txt");
//Writing the contents to the file
myfile <<"The Sum of Multiples of 2 or 5 is :"<
Solution
num.txt(Save this file under D Drive.Then the path of the file is D: um.txt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
CPP Code
#include
#include
using namespace std;
//Declaring Global variable
int sum=0;
//Function declarations
void readFromFile();
void writeToFile();
/* Function implementation which will
* read the numbers from the file and calculates the sum of
* the numbers which are multiples of 2 or 5
*/
void readFromFile()
{
int number,sum=0;
//fileInput reference
ifstream dataIn;
//Opening input file
dataIn.open("D: um.txt");
while(dataIn>>number)
{
if(number%2==0 || number%5==0)
{
sum+=number;
}
}
//closing the input stream
dataIn.close();
}
/* Function implementation which will
* display the sum into another text file
*/
void writeToFile()
{
//fileoutput reference
ofstream myfile;
//Opening the file
myfile.open ("D: um1.txt");
//Writing the contents to the file
myfile <<"The Sum of Multiples of 2 or 5 is :"<

More Related Content

Similar to num.txt(Save this file under D Drive.Then the path of the file is D.pdf

Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
mrecedu
 
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDYC UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
Rajeshkumar Reddy
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
radhushri
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfQuestion 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdf
anjandavid
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
CIS321
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
pinkpreet_kaur
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
pinkpreet_kaur
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
anandatalapatra
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-file
Deepak Singh
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
ChereCheek752
 

Similar to num.txt(Save this file under D Drive.Then the path of the file is D.pdf (20)

Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
 
slides3_077.ppt
slides3_077.pptslides3_077.ppt
slides3_077.ppt
 
C Language Unit-5
C Language Unit-5C Language Unit-5
C Language Unit-5
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handling
 
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDYC UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
Data Structure Using C - FILES
Data Structure Using C - FILESData Structure Using C - FILES
Data Structure Using C - FILES
 
WK-12-13-file f classs 12 computer science from kv.
WK-12-13-file f classs 12 computer science from kv.WK-12-13-file f classs 12 computer science from kv.
WK-12-13-file f classs 12 computer science from kv.
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfQuestion 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdf
 
file.ppt
file.pptfile.ppt
file.ppt
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-file
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 

More from ANSAPPARELS

Yes, I do agree, that some eukaryotic cells survive only on the reso.pdf
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdfYes, I do agree, that some eukaryotic cells survive only on the reso.pdf
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdf
ANSAPPARELS
 
What are the key components of an internal audit What are the impli.pdf
What are the key components of an internal audit What are the impli.pdfWhat are the key components of an internal audit What are the impli.pdf
What are the key components of an internal audit What are the impli.pdf
ANSAPPARELS
 
To differentiate between the mutated and normal genes, the DNA of th.pdf
To differentiate between the mutated and normal genes, the DNA of th.pdfTo differentiate between the mutated and normal genes, the DNA of th.pdf
To differentiate between the mutated and normal genes, the DNA of th.pdf
ANSAPPARELS
 
The data is Quantitative as there are numbers , and its an observati.pdf
The data is Quantitative as there are numbers , and its an observati.pdfThe data is Quantitative as there are numbers , and its an observati.pdf
The data is Quantitative as there are numbers , and its an observati.pdf
ANSAPPARELS
 
Solution1 ) The purpose of criminal law is to help maintain social.pdf
Solution1 ) The purpose of criminal law is to help maintain social.pdfSolution1 ) The purpose of criminal law is to help maintain social.pdf
Solution1 ) The purpose of criminal law is to help maintain social.pdf
ANSAPPARELS
 
Information security means protecting information (data) and informa.pdf
Information security means protecting information (data) and informa.pdfInformation security means protecting information (data) and informa.pdf
Information security means protecting information (data) and informa.pdf
ANSAPPARELS
 

More from ANSAPPARELS (20)

yes, roasting essentially means heating the ore, .pdf
                     yes, roasting essentially means heating the ore, .pdf                     yes, roasting essentially means heating the ore, .pdf
yes, roasting essentially means heating the ore, .pdf
 
There is no figure,Please upload it .pdf
                     There is no figure,Please upload it              .pdf                     There is no figure,Please upload it              .pdf
There is no figure,Please upload it .pdf
 
The adition is slow because the benzyne formed is.pdf
                     The adition is slow because the benzyne formed is.pdf                     The adition is slow because the benzyne formed is.pdf
The adition is slow because the benzyne formed is.pdf
 
only 1(I) .pdf
                     only 1(I)                                      .pdf                     only 1(I)                                      .pdf
only 1(I) .pdf
 
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdf
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdfYes, I do agree, that some eukaryotic cells survive only on the reso.pdf
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdf
 
What are the key components of an internal audit What are the impli.pdf
What are the key components of an internal audit What are the impli.pdfWhat are the key components of an internal audit What are the impli.pdf
What are the key components of an internal audit What are the impli.pdf
 
IV I II III Solution .pdf
                     IV  I  II  III   Solution                 .pdf                     IV  I  II  III   Solution                 .pdf
IV I II III Solution .pdf
 
To differentiate between the mutated and normal genes, the DNA of th.pdf
To differentiate between the mutated and normal genes, the DNA of th.pdfTo differentiate between the mutated and normal genes, the DNA of th.pdf
To differentiate between the mutated and normal genes, the DNA of th.pdf
 
The most critical shortcomings of these assumptions are1.The flow .pdf
The most critical shortcomings of these assumptions are1.The flow .pdfThe most critical shortcomings of these assumptions are1.The flow .pdf
The most critical shortcomings of these assumptions are1.The flow .pdf
 
The following statements are true1. The tendency of water to mini.pdf
The following statements are true1. The tendency of water to mini.pdfThe following statements are true1. The tendency of water to mini.pdf
The following statements are true1. The tendency of water to mini.pdf
 
The data is Quantitative as there are numbers , and its an observati.pdf
The data is Quantitative as there are numbers , and its an observati.pdfThe data is Quantitative as there are numbers , and its an observati.pdf
The data is Quantitative as there are numbers , and its an observati.pdf
 
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdf
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdfThank you everyone! The answer was O(n!)SolutionThank you ever.pdf
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdf
 
Solution1 ) The purpose of criminal law is to help maintain social.pdf
Solution1 ) The purpose of criminal law is to help maintain social.pdfSolution1 ) The purpose of criminal law is to help maintain social.pdf
Solution1 ) The purpose of criminal law is to help maintain social.pdf
 
question not visibleSolutionquestion not visible.pdf
question not visibleSolutionquestion not visible.pdfquestion not visibleSolutionquestion not visible.pdf
question not visibleSolutionquestion not visible.pdf
 
n = 7 which is odd so median is the middle value of te data after ar.pdf
n = 7 which is odd so median is the middle value of te data after ar.pdfn = 7 which is odd so median is the middle value of te data after ar.pdf
n = 7 which is odd so median is the middle value of te data after ar.pdf
 
Molybdenum is the elementSolutionMolybdenum is the element.pdf
Molybdenum is the elementSolutionMolybdenum is the element.pdfMolybdenum is the elementSolutionMolybdenum is the element.pdf
Molybdenum is the elementSolutionMolybdenum is the element.pdf
 
Mean absolute deviationSolutionMean absolute deviation.pdf
Mean absolute deviationSolutionMean absolute deviation.pdfMean absolute deviationSolutionMean absolute deviation.pdf
Mean absolute deviationSolutionMean absolute deviation.pdf
 
elements involved are C and N .pdf
                     elements involved are C and N                    .pdf                     elements involved are C and N                    .pdf
elements involved are C and N .pdf
 
Information security means protecting information (data) and informa.pdf
Information security means protecting information (data) and informa.pdfInformation security means protecting information (data) and informa.pdf
Information security means protecting information (data) and informa.pdf
 
Given that T is unitaryT = 1I-ieH =1det (-T) = (-1)ndet T.pdf
Given that T is unitaryT = 1I-ieH =1det (-T) = (-1)ndet T.pdfGiven that T is unitaryT = 1I-ieH =1det (-T) = (-1)ndet T.pdf
Given that T is unitaryT = 1I-ieH =1det (-T) = (-1)ndet T.pdf
 

Recently uploaded

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
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
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.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
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

num.txt(Save this file under D Drive.Then the path of the file is D.pdf

  • 1. num.txt(Save this file under D Drive.Then the path of the file is D: um.txt) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 CPP Code #include #include using namespace std; //Declaring Global variable int sum=0; //Function declarations void readFromFile(); void writeToFile(); /* Function implementation which will * read the numbers from the file and calculates the sum of * the numbers which are multiples of 2 or 5 */ void readFromFile()
  • 2. { int number,sum=0; //fileInput reference ifstream dataIn; //Opening input file dataIn.open("D: um.txt"); while(dataIn>>number) { if(number%2==0 || number%5==0) { sum+=number; } } //closing the input stream dataIn.close(); } /* Function implementation which will * display the sum into another text file */ void writeToFile() { //fileoutput reference ofstream myfile; //Opening the file myfile.open ("D: um1.txt"); //Writing the contents to the file myfile <<"The Sum of Multiples of 2 or 5 is :"< Solution num.txt(Save this file under D Drive.Then the path of the file is D: um.txt) 1 2
  • 3. 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 CPP Code #include #include using namespace std; //Declaring Global variable int sum=0; //Function declarations void readFromFile(); void writeToFile(); /* Function implementation which will * read the numbers from the file and calculates the sum of * the numbers which are multiples of 2 or 5 */ void readFromFile() { int number,sum=0; //fileInput reference
  • 4. ifstream dataIn; //Opening input file dataIn.open("D: um.txt"); while(dataIn>>number) { if(number%2==0 || number%5==0) { sum+=number; } } //closing the input stream dataIn.close(); } /* Function implementation which will * display the sum into another text file */ void writeToFile() { //fileoutput reference ofstream myfile; //Opening the file myfile.open ("D: um1.txt"); //Writing the contents to the file myfile <<"The Sum of Multiples of 2 or 5 is :"<