SlideShare a Scribd company logo
1 of 4
Download to read offline
Please follow the code and comments for description :
a)
CODE :
#include // header file
using namespace std;
double factorial(double n); // required method with the double value
int main() // main method
{
int n;
cout << "Enter a positive integer: "; // prompt to get the integer value
cin >> n;
cout << "Factorial of " << n << " = " << factorial(n); // calluing the function
return 0;
}
double factorial(double n)
{
if(n!=1)
return n*factorial(n-1); // returning the result
}
OUTPUT :
Enter a positive integer: 6
Factorial of 6 = 720
b)
CODE :
#include // header file
#include
using namespace std;
int main() // main method
{
int count = 0; // required initialisations
string line;
ifstream file("input.txt"); //Creating input filestream
while (getline(file, line)){ // iterating over the loop to get the data and count
count++;
cout << line << endl; // printing the data
}
cout << "Numbers of lines in the file : " << count << endl; // print the count
return 0;
}
input.txt :
Hi
Hello
How are You
Hope Your are Doing Good
See You
Tomorrow
Good Bye
Meet
You
LAter
OUTPUT :
Hi
Hello
How are You
Hope Your are Doing Good
See You
Tomorrow
Good Bye
Meet
You
LAter
Numbers of lines in the file : 10
Hope this is helpful.
Solution
Please follow the code and comments for description :
a)
CODE :
#include // header file
using namespace std;
double factorial(double n); // required method with the double value
int main() // main method
{
int n;
cout << "Enter a positive integer: "; // prompt to get the integer value
cin >> n;
cout << "Factorial of " << n << " = " << factorial(n); // calluing the function
return 0;
}
double factorial(double n)
{
if(n!=1)
return n*factorial(n-1); // returning the result
}
OUTPUT :
Enter a positive integer: 6
Factorial of 6 = 720
b)
CODE :
#include // header file
#include
using namespace std;
int main() // main method
{
int count = 0; // required initialisations
string line;
ifstream file("input.txt"); //Creating input filestream
while (getline(file, line)){ // iterating over the loop to get the data and count
count++;
cout << line << endl; // printing the data
}
cout << "Numbers of lines in the file : " << count << endl; // print the count
return 0;
}
input.txt :
Hi
Hello
How are You
Hope Your are Doing Good
See You
Tomorrow
Good Bye
Meet
You
LAter
OUTPUT :
Hi
Hello
How are You
Hope Your are Doing Good
See You
Tomorrow
Good Bye
Meet
You
LAter
Numbers of lines in the file : 10
Hope this is helpful.

More Related Content

Similar to Please follow the code and comments for description a)CODE #.pdf

C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
aassecuritysystem
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
radhushri
 
File & Exception Handling in C++.pptx
File & Exception Handling in C++.pptxFile & Exception Handling in C++.pptx
File & Exception Handling in C++.pptx
RutujaTandalwade
 
Use the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfUse the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdf
sales87
 
#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
 

Similar to Please follow the code and comments for description a)CODE #.pdf (20)

C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
How c/c++ works
How c/c++ worksHow c/c++ works
How c/c++ works
 
A function definition num_digits with Cpp programnum_digits.cpp#.pdf
A function definition num_digits with Cpp programnum_digits.cpp#.pdfA function definition num_digits with Cpp programnum_digits.cpp#.pdf
A function definition num_digits with Cpp programnum_digits.cpp#.pdf
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
C++ Programs
C++ ProgramsC++ Programs
C++ Programs
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
 
File & Exception Handling in C++.pptx
File & Exception Handling in C++.pptxFile & Exception Handling in C++.pptx
File & Exception Handling in C++.pptx
 
Pointers
PointersPointers
Pointers
 
P1
P1P1
P1
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Use the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfUse the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.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
#include iostream #include cstring #include vector #i.pdf
 
need help with my computer science lab assignemnt. this assignment i.pdf
need help with my computer science lab assignemnt. this assignment i.pdfneed help with my computer science lab assignemnt. this assignment i.pdf
need help with my computer science lab assignemnt. this assignment i.pdf
 
Cgi
CgiCgi
Cgi
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
Bubble in link list
Bubble in link listBubble in link list
Bubble in link list
 
C++ Programm.pptx
C++ Programm.pptxC++ Programm.pptx
C++ Programm.pptx
 
FUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptxFUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptx
 
I need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdfI need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdf
 
CPP Quiz
CPP QuizCPP Quiz
CPP Quiz
 

More from annaindustries

Im not entirely sure what this is asking. I ass.pdf
                     Im not entirely sure what this is asking. I ass.pdf                     Im not entirely sure what this is asking. I ass.pdf
Im not entirely sure what this is asking. I ass.pdf
annaindustries
 
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdfViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
annaindustries
 
First remember that non polar compounds are solub.pdf
                     First remember that non polar compounds are solub.pdf                     First remember that non polar compounds are solub.pdf
First remember that non polar compounds are solub.pdf
annaindustries
 
Photosynthesis - is the unique process that is limited to plant king.pdf
Photosynthesis - is the unique process that is limited to plant king.pdfPhotosynthesis - is the unique process that is limited to plant king.pdf
Photosynthesis - is the unique process that is limited to plant king.pdf
annaindustries
 
Optimized Waterfall processIs a common project methodology and it.pdf
Optimized Waterfall processIs a common project methodology and it.pdfOptimized Waterfall processIs a common project methodology and it.pdf
Optimized Waterfall processIs a common project methodology and it.pdf
annaindustries
 
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdfOrganism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
annaindustries
 
It is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdfIt is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdf
annaindustries
 

More from annaindustries (20)

This is Due to highest Cncentration of Comon Ions.pdf
                     This is Due to highest Cncentration of Comon Ions.pdf                     This is Due to highest Cncentration of Comon Ions.pdf
This is Due to highest Cncentration of Comon Ions.pdf
 
There is no reaction. The nearest I can think of .pdf
                     There is no reaction. The nearest I can think of .pdf                     There is no reaction. The nearest I can think of .pdf
There is no reaction. The nearest I can think of .pdf
 
The decomposition of hydrogen peroxide to gaseous.pdf
                     The decomposition of hydrogen peroxide to gaseous.pdf                     The decomposition of hydrogen peroxide to gaseous.pdf
The decomposition of hydrogen peroxide to gaseous.pdf
 
NaBr Na is metal and Br is electronegative. All.pdf
                     NaBr  Na is metal and Br is electronegative.  All.pdf                     NaBr  Na is metal and Br is electronegative.  All.pdf
NaBr Na is metal and Br is electronegative. All.pdf
 
it is not hydrolyzed because of steric hindrance .pdf
                     it is not hydrolyzed because of steric hindrance .pdf                     it is not hydrolyzed because of steric hindrance .pdf
it is not hydrolyzed because of steric hindrance .pdf
 
Im not entirely sure what this is asking. I ass.pdf
                     Im not entirely sure what this is asking. I ass.pdf                     Im not entirely sure what this is asking. I ass.pdf
Im not entirely sure what this is asking. I ass.pdf
 
HI = hydrogen iodide .pdf
                     HI = hydrogen iodide                             .pdf                     HI = hydrogen iodide                             .pdf
HI = hydrogen iodide .pdf
 
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdfViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
 
Z = (x-mean)sd = (82-70)8 = 1.50SolutionZ = (x-mean)sd = (8.pdf
Z = (x-mean)sd = (82-70)8 = 1.50SolutionZ = (x-mean)sd = (8.pdfZ = (x-mean)sd = (82-70)8 = 1.50SolutionZ = (x-mean)sd = (8.pdf
Z = (x-mean)sd = (82-70)8 = 1.50SolutionZ = (x-mean)sd = (8.pdf
 
First remember that non polar compounds are solub.pdf
                     First remember that non polar compounds are solub.pdf                     First remember that non polar compounds are solub.pdf
First remember that non polar compounds are solub.pdf
 
There are many types of malwares like Trojans, viruses, worms, rootk.pdf
There are many types of malwares like Trojans, viruses, worms, rootk.pdfThere are many types of malwares like Trojans, viruses, worms, rootk.pdf
There are many types of malwares like Trojans, viruses, worms, rootk.pdf
 
The standard form of a complex number is a real number plusminus an.pdf
The standard form of a complex number is a real number plusminus an.pdfThe standard form of a complex number is a real number plusminus an.pdf
The standard form of a complex number is a real number plusminus an.pdf
 
DNA and RNA .pdf
                     DNA and RNA                                      .pdf                     DNA and RNA                                      .pdf
DNA and RNA .pdf
 
Solution-1. For this weSolutionSolution-1. For this we.pdf
Solution-1. For this weSolutionSolution-1. For this we.pdfSolution-1. For this weSolutionSolution-1. For this we.pdf
Solution-1. For this weSolutionSolution-1. For this we.pdf
 
Question) one or more attributes that comprise a primary key in a ro.pdf
Question) one or more attributes that comprise a primary key in a ro.pdfQuestion) one or more attributes that comprise a primary key in a ro.pdf
Question) one or more attributes that comprise a primary key in a ro.pdf
 
pls provide the dataSolutionpls provide the data.pdf
pls provide the dataSolutionpls provide the data.pdfpls provide the dataSolutionpls provide the data.pdf
pls provide the dataSolutionpls provide the data.pdf
 
Photosynthesis - is the unique process that is limited to plant king.pdf
Photosynthesis - is the unique process that is limited to plant king.pdfPhotosynthesis - is the unique process that is limited to plant king.pdf
Photosynthesis - is the unique process that is limited to plant king.pdf
 
Optimized Waterfall processIs a common project methodology and it.pdf
Optimized Waterfall processIs a common project methodology and it.pdfOptimized Waterfall processIs a common project methodology and it.pdf
Optimized Waterfall processIs a common project methodology and it.pdf
 
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdfOrganism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
 
It is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdfIt is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
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
 

Recently uploaded (20)

Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
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
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
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
 
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
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .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...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

Please follow the code and comments for description a)CODE #.pdf

  • 1. Please follow the code and comments for description : a) CODE : #include // header file using namespace std; double factorial(double n); // required method with the double value int main() // main method { int n; cout << "Enter a positive integer: "; // prompt to get the integer value cin >> n; cout << "Factorial of " << n << " = " << factorial(n); // calluing the function return 0; } double factorial(double n) { if(n!=1) return n*factorial(n-1); // returning the result } OUTPUT : Enter a positive integer: 6 Factorial of 6 = 720 b) CODE : #include // header file #include using namespace std; int main() // main method { int count = 0; // required initialisations string line; ifstream file("input.txt"); //Creating input filestream
  • 2. while (getline(file, line)){ // iterating over the loop to get the data and count count++; cout << line << endl; // printing the data } cout << "Numbers of lines in the file : " << count << endl; // print the count return 0; } input.txt : Hi Hello How are You Hope Your are Doing Good See You Tomorrow Good Bye Meet You LAter OUTPUT : Hi Hello How are You Hope Your are Doing Good See You Tomorrow Good Bye Meet You LAter Numbers of lines in the file : 10 Hope this is helpful.
  • 3. Solution Please follow the code and comments for description : a) CODE : #include // header file using namespace std; double factorial(double n); // required method with the double value int main() // main method { int n; cout << "Enter a positive integer: "; // prompt to get the integer value cin >> n; cout << "Factorial of " << n << " = " << factorial(n); // calluing the function return 0; } double factorial(double n) { if(n!=1) return n*factorial(n-1); // returning the result } OUTPUT : Enter a positive integer: 6 Factorial of 6 = 720 b) CODE : #include // header file #include using namespace std; int main() // main method { int count = 0; // required initialisations string line;
  • 4. ifstream file("input.txt"); //Creating input filestream while (getline(file, line)){ // iterating over the loop to get the data and count count++; cout << line << endl; // printing the data } cout << "Numbers of lines in the file : " << count << endl; // print the count return 0; } input.txt : Hi Hello How are You Hope Your are Doing Good See You Tomorrow Good Bye Meet You LAter OUTPUT : Hi Hello How are You Hope Your are Doing Good See You Tomorrow Good Bye Meet You LAter Numbers of lines in the file : 10 Hope this is helpful.