SlideShare a Scribd company logo
1 of 6
Download to read offline
Tffff
The program needs to be in C++ and part 1 of the assignment is already done. The only
difference is that the appropriate text files that will be used for this program... some of them are
large txt files (chapter of a book for example to almost a complete book).
Part 2 is the Question!!!
The code for part one is shown below:
#include // required header files
#include
#include
using namespace std;
int main() // driver method
{
string myArray[100]; // array to store the data
string filename; //required initialisations
ifstream file;
int count = 0;
cout << "Please enter the input file name: "; // prompt for the user to enter the filename
cin >> filename;
filename = filename+".txt";
file.open( filename.c_str() ); // opening the filename
if(file.is_open()) // checking for the opening of the file
{
while ( !file.eof() ){
count++; // incrementing the count for the lines
for(int x = 0; x < count; x++){
file >> myArray[x]; // saving the data to the array
cout << "The Array Data is : " << myArray[x] << endl; // printing the output to console
}
}
file.close(); // closing the file
} else {
cout << "Error Opening the File!!" << endl; // catching the exception
}
cout << " The total Words in the file are : " << count << endl; // getting the count from the
lines
return 0;
}
OUTPUT :
Please enter the input file name: input
The Array Data is : John
The Array Data is : Carter
The Array Data is : Harry
The Array Data is : Mornie
The Array Data is : Michael
The Array Data is : Mary
The Array Data is : Newton
The total Words in the file are : 7
Now from this code, how can we adjust it so part 2 from the assignment fits in.
Solution
Please follow the code and comments for description :
CODE :
#include // required header files
#include
#include
#include
using namespace std;
int main() // driver method
{
string myArray[100]; // array to store the data
string filename, line; //required initialisations
ifstream file;
int count = 0, index = 0, occurrence = 0, foundOcc = 0;
cout << "Please enter the input file name: "; // prompt for the user to enter the filename
cin >> filename;
filename = filename+".txt";
file.open( filename.c_str() ); // opening the filename
if(file.is_open()) // checking for the opening of the file
{
while ( !file.eof() ){
count++; // incrementing the count for the lines
for(int x = count; x <= count; x++){
index = index + 1;
file >> myArray[x]; // saving the data to the array
cout << "The Data is : " << myArray[x] << " found at index value : " << index <<
endl; // printing the output to console
}
}
file.close(); // closing the file
} else {
cout << "Error Opening the File!!" << endl; // catching the exception
}
for (int i = 1; i <= count; i++) {
// checking to the data in the array if it was used before
int found = 0;
for (int j = 0; j < i; j++) {
if (myArray[i] == myArray[j]) {
found++;
}
}
// continuing if it's the first occurrence
if (found == 0) {
// starting the count with initial value
occurrence = 1;
// checking the data in the array for other occurances
for (int j = i + 1; j < 8; j++) {
if (myArray[i] == myArray[j]) {
occurrence++;
}
}
cout << " Occurrences of the Word " << myArray[i] << " is : "; // printing the number
of occurances
cout << myArray[i] << " : " << occurrence << endl; // printing the data of the array
float percent = (float)(occurrence*100)/count; // calculating the percent of the occurances
cout << "Percentage of Occurrence of the Word " << myArray[i] << " is : " << percent
<< "%" << endl; // printing the data and the percent of occurrence
if(occurrence > 1){
foundOcc++; // calculating the total occurrences in the file
}
}
}
cout << " Number of Occurrences Found in the data read are : " << foundOcc << endl; //
printing the results
cout << " The total Words in the file are : " << count << endl; // getting the count from the
lines
return 0;
}
input.txt :
John
Miller
Carter
Penny
Carter
Bill
Harry
Shawn
Perk
Cameroon
Bush
Moore
Mary
Marxter
OUTPUT :
Please enter the input file name: input
The Data is : John found at index value : 1
The Data is : Miller found at index value : 2
The Data is : Carter found at index value : 3
The Data is : Penny found at index value : 4
The Data is : Carter found at index value : 5
The Data is : Bill found at index value : 6
The Data is : Harry found at index value : 7
The Data is : Shawn found at index value : 8
The Data is : Perk found at index value : 9
The Data is : Cameroon found at index value : 10
The Data is : Bush found at index value : 11
The Data is : Moore found at index value : 12
The Data is : Mary found at index value : 13
The Data is : Marxter found at index value :
14
Occurrences of the Word John is : John : 1
Percentage of Occurrence of the Word John is : 7.14286%
Occurrences of the Word Miller is : Miller : 1
Percentage of Occurrence of the Word Miller is : 7.14286%
Occurrences of the Word Carter is : Carter : 2
Percentage of Occurrence of the Word Carter is : 14.2857%
Occurrences of the Word Penny is : Penny : 1
Percentage of Occurrence of the Word Penny is : 7.14286%
Occurrences of the Word Bill is : Bill : 1
Percentage of Occurrence of the Word Bill is : 7.14286%
Occurrences of the Word Harry is : Harry : 1
Percentage of Occurrence of the Word Harry is : 7.14286%
Occurrences of the Word Shawn is : Shawn : 1
Percentage of Occurrence of the Word Shawn is : 7.14286%
Occurrences of the Word Perk is : Perk : 1
Percentage of Occurrence of the Word Perk is : 7.14286%
Occurrences of the Word Cameroon is : Cameroon : 1
Percentage of Occurrence of the Word Cameroon is : 7.14286%
Occurrences of the Word Bush is : Bush : 1
Percentage of Occurrence of the Word Bush is : 7.14286%
Occurrences of the Word Moore is : Moore : 1
Percentage of Occurrence of the Word Moore is : 7.14286%
Occurrences of the Word Mary is : Mary : 1
Percentage of Occurrence of the Word Mary is : 7.14286%
Occurrences of the Word Marxter is : Marxter : 1
Percentage of Occurrence of the Word Marxter is : 7.14286%
Number of Occurrences Found in the data read are : 1
The total Words in the file are : 14
Hope this is helpful.

More Related Content

Similar to TffffThe program needs to be in C++ and part 1 of the assignment i.pdf

UNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CUNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CRaj vardhan
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfezonesolutions
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptxradhushri
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfaratextails30
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfSANDEEPARIHANT
 
source code which create file and write into it
source code which create file and write into itsource code which create file and write into it
source code which create file and write into itmelakusisay507
 
Write a program that asks the user for the name of a file. The progra.docx
 Write a program that asks the user for the name of a file. The progra.docx Write a program that asks the user for the name of a file. The progra.docx
Write a program that asks the user for the name of a file. The progra.docxajoy21
 
Cs1123 10 file operations
Cs1123 10 file operationsCs1123 10 file operations
Cs1123 10 file operationsTAlha MAlik
 
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 REDDYRajeshkumar Reddy
 
Read write program
Read write programRead write program
Read write programAMI AMITO
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examplesMuhammed Thanveer M
 

Similar to TffffThe program needs to be in C++ and part 1 of the assignment i.pdf (20)

UNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CUNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN C
 
PPS-II UNIT-5 PPT.pptx
PPS-II  UNIT-5 PPT.pptxPPS-II  UNIT-5 PPT.pptx
PPS-II UNIT-5 PPT.pptx
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
Unit5
Unit5Unit5
Unit5
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdf
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
 
source code which create file and write into it
source code which create file and write into itsource code which create file and write into it
source code which create file and write into it
 
Write a program that asks the user for the name of a file. The progra.docx
 Write a program that asks the user for the name of a file. The progra.docx Write a program that asks the user for the name of a file. The progra.docx
Write a program that asks the user for the name of a file. The progra.docx
 
Cs1123 10 file operations
Cs1123 10 file operationsCs1123 10 file operations
Cs1123 10 file operations
 
Fileinc
FileincFileinc
Fileinc
 
file.ppt
file.pptfile.ppt
file.ppt
 
File management
File managementFile management
File management
 
Data structures
Data structuresData structures
Data structures
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
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 management
File managementFile management
File management
 
Read write program
Read write programRead write program
Read write program
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examples
 

More from arri2009av

Identify five muscles of the head area that have a name that is very .pdf
Identify five muscles of the head area that have a name that is very .pdfIdentify five muscles of the head area that have a name that is very .pdf
Identify five muscles of the head area that have a name that is very .pdfarri2009av
 
Identify non-neoplastic conditions effecting pregnancy. Describe STI.pdf
Identify non-neoplastic conditions effecting pregnancy. Describe STI.pdfIdentify non-neoplastic conditions effecting pregnancy. Describe STI.pdf
Identify non-neoplastic conditions effecting pregnancy. Describe STI.pdfarri2009av
 
From a mixed field, what is easier to facilitate through artificial s.pdf
From a mixed field, what is easier to facilitate through artificial s.pdfFrom a mixed field, what is easier to facilitate through artificial s.pdf
From a mixed field, what is easier to facilitate through artificial s.pdfarri2009av
 
Explain how you would tell if something that looks like a leaf (flat.pdf
Explain how you would tell if something that looks like a leaf (flat.pdfExplain how you would tell if something that looks like a leaf (flat.pdf
Explain how you would tell if something that looks like a leaf (flat.pdfarri2009av
 
Explain what a standard deviation value measures in quantitative dat.pdf
Explain what a standard deviation value measures in quantitative dat.pdfExplain what a standard deviation value measures in quantitative dat.pdf
Explain what a standard deviation value measures in quantitative dat.pdfarri2009av
 
Einstein, in his famous photoelectric effect experiment demonstr.pdf
Einstein, in his famous photoelectric effect experiment demonstr.pdfEinstein, in his famous photoelectric effect experiment demonstr.pdf
Einstein, in his famous photoelectric effect experiment demonstr.pdfarri2009av
 
Contrast autochthonous and allochthonous food webs. Which type would.pdf
Contrast autochthonous and allochthonous food webs. Which type would.pdfContrast autochthonous and allochthonous food webs. Which type would.pdf
Contrast autochthonous and allochthonous food webs. Which type would.pdfarri2009av
 
Based on the below and using the 12 categories of threats identify 3 .pdf
Based on the below and using the 12 categories of threats identify 3 .pdfBased on the below and using the 12 categories of threats identify 3 .pdf
Based on the below and using the 12 categories of threats identify 3 .pdfarri2009av
 
Blair, R. B. 1996. Land use and avian species diversity along an urb.pdf
Blair, R. B. 1996. Land use and avian species diversity along an urb.pdfBlair, R. B. 1996. Land use and avian species diversity along an urb.pdf
Blair, R. B. 1996. Land use and avian species diversity along an urb.pdfarri2009av
 
An attack in which an authentic-looking e-mail or website entices a .pdf
An attack in which an authentic-looking e-mail or website entices a .pdfAn attack in which an authentic-looking e-mail or website entices a .pdf
An attack in which an authentic-looking e-mail or website entices a .pdfarri2009av
 
Consider a relation T with six attributes ABCDEF where AB is a compo.pdf
Consider a relation T with six attributes ABCDEF where AB is a compo.pdfConsider a relation T with six attributes ABCDEF where AB is a compo.pdf
Consider a relation T with six attributes ABCDEF where AB is a compo.pdfarri2009av
 
A vague appointment Four people make an appointment to meet each ot.pdf
A vague appointment Four people make an appointment to meet each ot.pdfA vague appointment Four people make an appointment to meet each ot.pdf
A vague appointment Four people make an appointment to meet each ot.pdfarri2009av
 
Assume real numbers R for now. Consider relation on R, x y iff x .pdf
Assume real numbers R for now. Consider relation  on R, x  y iff x  .pdfAssume real numbers R for now. Consider relation  on R, x  y iff x  .pdf
Assume real numbers R for now. Consider relation on R, x y iff x .pdfarri2009av
 
An enzyme aggase requires 16 units of activity for wild type functio.pdf
An enzyme aggase requires 16 units of activity for wild type functio.pdfAn enzyme aggase requires 16 units of activity for wild type functio.pdf
An enzyme aggase requires 16 units of activity for wild type functio.pdfarri2009av
 
17. Of these, which represents a heterozygote a. aa b. Ab c. .pdf
17. Of these, which represents a heterozygote a. aa b. Ab c. .pdf17. Of these, which represents a heterozygote a. aa b. Ab c. .pdf
17. Of these, which represents a heterozygote a. aa b. Ab c. .pdfarri2009av
 
1. Match the decription listed with the corresponding structureA. .pdf
1. Match the decription listed with the corresponding structureA. .pdf1. Match the decription listed with the corresponding structureA. .pdf
1. Match the decription listed with the corresponding structureA. .pdfarri2009av
 
1.) What are some factors that should be taken into account when est.pdf
1.) What are some factors that should be taken into account when est.pdf1.) What are some factors that should be taken into account when est.pdf
1.) What are some factors that should be taken into account when est.pdfarri2009av
 
Write a program that asks the user for the name of a file. The progr.pdf
Write a program that asks the user for the name of a file. The progr.pdfWrite a program that asks the user for the name of a file. The progr.pdf
Write a program that asks the user for the name of a file. The progr.pdfarri2009av
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfarri2009av
 
Wings of bats area. Plesiomorphic (ancestral) feature for mammals.pdf
Wings of bats area. Plesiomorphic (ancestral) feature for mammals.pdfWings of bats area. Plesiomorphic (ancestral) feature for mammals.pdf
Wings of bats area. Plesiomorphic (ancestral) feature for mammals.pdfarri2009av
 

More from arri2009av (20)

Identify five muscles of the head area that have a name that is very .pdf
Identify five muscles of the head area that have a name that is very .pdfIdentify five muscles of the head area that have a name that is very .pdf
Identify five muscles of the head area that have a name that is very .pdf
 
Identify non-neoplastic conditions effecting pregnancy. Describe STI.pdf
Identify non-neoplastic conditions effecting pregnancy. Describe STI.pdfIdentify non-neoplastic conditions effecting pregnancy. Describe STI.pdf
Identify non-neoplastic conditions effecting pregnancy. Describe STI.pdf
 
From a mixed field, what is easier to facilitate through artificial s.pdf
From a mixed field, what is easier to facilitate through artificial s.pdfFrom a mixed field, what is easier to facilitate through artificial s.pdf
From a mixed field, what is easier to facilitate through artificial s.pdf
 
Explain how you would tell if something that looks like a leaf (flat.pdf
Explain how you would tell if something that looks like a leaf (flat.pdfExplain how you would tell if something that looks like a leaf (flat.pdf
Explain how you would tell if something that looks like a leaf (flat.pdf
 
Explain what a standard deviation value measures in quantitative dat.pdf
Explain what a standard deviation value measures in quantitative dat.pdfExplain what a standard deviation value measures in quantitative dat.pdf
Explain what a standard deviation value measures in quantitative dat.pdf
 
Einstein, in his famous photoelectric effect experiment demonstr.pdf
Einstein, in his famous photoelectric effect experiment demonstr.pdfEinstein, in his famous photoelectric effect experiment demonstr.pdf
Einstein, in his famous photoelectric effect experiment demonstr.pdf
 
Contrast autochthonous and allochthonous food webs. Which type would.pdf
Contrast autochthonous and allochthonous food webs. Which type would.pdfContrast autochthonous and allochthonous food webs. Which type would.pdf
Contrast autochthonous and allochthonous food webs. Which type would.pdf
 
Based on the below and using the 12 categories of threats identify 3 .pdf
Based on the below and using the 12 categories of threats identify 3 .pdfBased on the below and using the 12 categories of threats identify 3 .pdf
Based on the below and using the 12 categories of threats identify 3 .pdf
 
Blair, R. B. 1996. Land use and avian species diversity along an urb.pdf
Blair, R. B. 1996. Land use and avian species diversity along an urb.pdfBlair, R. B. 1996. Land use and avian species diversity along an urb.pdf
Blair, R. B. 1996. Land use and avian species diversity along an urb.pdf
 
An attack in which an authentic-looking e-mail or website entices a .pdf
An attack in which an authentic-looking e-mail or website entices a .pdfAn attack in which an authentic-looking e-mail or website entices a .pdf
An attack in which an authentic-looking e-mail or website entices a .pdf
 
Consider a relation T with six attributes ABCDEF where AB is a compo.pdf
Consider a relation T with six attributes ABCDEF where AB is a compo.pdfConsider a relation T with six attributes ABCDEF where AB is a compo.pdf
Consider a relation T with six attributes ABCDEF where AB is a compo.pdf
 
A vague appointment Four people make an appointment to meet each ot.pdf
A vague appointment Four people make an appointment to meet each ot.pdfA vague appointment Four people make an appointment to meet each ot.pdf
A vague appointment Four people make an appointment to meet each ot.pdf
 
Assume real numbers R for now. Consider relation on R, x y iff x .pdf
Assume real numbers R for now. Consider relation  on R, x  y iff x  .pdfAssume real numbers R for now. Consider relation  on R, x  y iff x  .pdf
Assume real numbers R for now. Consider relation on R, x y iff x .pdf
 
An enzyme aggase requires 16 units of activity for wild type functio.pdf
An enzyme aggase requires 16 units of activity for wild type functio.pdfAn enzyme aggase requires 16 units of activity for wild type functio.pdf
An enzyme aggase requires 16 units of activity for wild type functio.pdf
 
17. Of these, which represents a heterozygote a. aa b. Ab c. .pdf
17. Of these, which represents a heterozygote a. aa b. Ab c. .pdf17. Of these, which represents a heterozygote a. aa b. Ab c. .pdf
17. Of these, which represents a heterozygote a. aa b. Ab c. .pdf
 
1. Match the decription listed with the corresponding structureA. .pdf
1. Match the decription listed with the corresponding structureA. .pdf1. Match the decription listed with the corresponding structureA. .pdf
1. Match the decription listed with the corresponding structureA. .pdf
 
1.) What are some factors that should be taken into account when est.pdf
1.) What are some factors that should be taken into account when est.pdf1.) What are some factors that should be taken into account when est.pdf
1.) What are some factors that should be taken into account when est.pdf
 
Write a program that asks the user for the name of a file. The progr.pdf
Write a program that asks the user for the name of a file. The progr.pdfWrite a program that asks the user for the name of a file. The progr.pdf
Write a program that asks the user for the name of a file. The progr.pdf
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
Wings of bats area. Plesiomorphic (ancestral) feature for mammals.pdf
Wings of bats area. Plesiomorphic (ancestral) feature for mammals.pdfWings of bats area. Plesiomorphic (ancestral) feature for mammals.pdf
Wings of bats area. Plesiomorphic (ancestral) feature for mammals.pdf
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

TffffThe program needs to be in C++ and part 1 of the assignment i.pdf

  • 1. Tffff The program needs to be in C++ and part 1 of the assignment is already done. The only difference is that the appropriate text files that will be used for this program... some of them are large txt files (chapter of a book for example to almost a complete book). Part 2 is the Question!!! The code for part one is shown below: #include // required header files #include #include using namespace std; int main() // driver method { string myArray[100]; // array to store the data string filename; //required initialisations ifstream file; int count = 0; cout << "Please enter the input file name: "; // prompt for the user to enter the filename cin >> filename; filename = filename+".txt"; file.open( filename.c_str() ); // opening the filename if(file.is_open()) // checking for the opening of the file { while ( !file.eof() ){ count++; // incrementing the count for the lines for(int x = 0; x < count; x++){ file >> myArray[x]; // saving the data to the array cout << "The Array Data is : " << myArray[x] << endl; // printing the output to console } } file.close(); // closing the file } else { cout << "Error Opening the File!!" << endl; // catching the exception
  • 2. } cout << " The total Words in the file are : " << count << endl; // getting the count from the lines return 0; } OUTPUT : Please enter the input file name: input The Array Data is : John The Array Data is : Carter The Array Data is : Harry The Array Data is : Mornie The Array Data is : Michael The Array Data is : Mary The Array Data is : Newton The total Words in the file are : 7 Now from this code, how can we adjust it so part 2 from the assignment fits in. Solution Please follow the code and comments for description : CODE : #include // required header files #include #include #include using namespace std; int main() // driver method { string myArray[100]; // array to store the data string filename, line; //required initialisations ifstream file; int count = 0, index = 0, occurrence = 0, foundOcc = 0; cout << "Please enter the input file name: "; // prompt for the user to enter the filename cin >> filename; filename = filename+".txt";
  • 3. file.open( filename.c_str() ); // opening the filename if(file.is_open()) // checking for the opening of the file { while ( !file.eof() ){ count++; // incrementing the count for the lines for(int x = count; x <= count; x++){ index = index + 1; file >> myArray[x]; // saving the data to the array cout << "The Data is : " << myArray[x] << " found at index value : " << index << endl; // printing the output to console } } file.close(); // closing the file } else { cout << "Error Opening the File!!" << endl; // catching the exception } for (int i = 1; i <= count; i++) { // checking to the data in the array if it was used before int found = 0; for (int j = 0; j < i; j++) { if (myArray[i] == myArray[j]) { found++; } } // continuing if it's the first occurrence if (found == 0) { // starting the count with initial value occurrence = 1; // checking the data in the array for other occurances for (int j = i + 1; j < 8; j++) { if (myArray[i] == myArray[j]) { occurrence++; } } cout << " Occurrences of the Word " << myArray[i] << " is : "; // printing the number of occurances
  • 4. cout << myArray[i] << " : " << occurrence << endl; // printing the data of the array float percent = (float)(occurrence*100)/count; // calculating the percent of the occurances cout << "Percentage of Occurrence of the Word " << myArray[i] << " is : " << percent << "%" << endl; // printing the data and the percent of occurrence if(occurrence > 1){ foundOcc++; // calculating the total occurrences in the file } } } cout << " Number of Occurrences Found in the data read are : " << foundOcc << endl; // printing the results cout << " The total Words in the file are : " << count << endl; // getting the count from the lines return 0; } input.txt : John Miller Carter Penny Carter Bill Harry Shawn Perk Cameroon Bush Moore Mary Marxter OUTPUT : Please enter the input file name: input The Data is : John found at index value : 1 The Data is : Miller found at index value : 2 The Data is : Carter found at index value : 3
  • 5. The Data is : Penny found at index value : 4 The Data is : Carter found at index value : 5 The Data is : Bill found at index value : 6 The Data is : Harry found at index value : 7 The Data is : Shawn found at index value : 8 The Data is : Perk found at index value : 9 The Data is : Cameroon found at index value : 10 The Data is : Bush found at index value : 11 The Data is : Moore found at index value : 12 The Data is : Mary found at index value : 13 The Data is : Marxter found at index value : 14 Occurrences of the Word John is : John : 1 Percentage of Occurrence of the Word John is : 7.14286% Occurrences of the Word Miller is : Miller : 1 Percentage of Occurrence of the Word Miller is : 7.14286% Occurrences of the Word Carter is : Carter : 2 Percentage of Occurrence of the Word Carter is : 14.2857% Occurrences of the Word Penny is : Penny : 1 Percentage of Occurrence of the Word Penny is : 7.14286% Occurrences of the Word Bill is : Bill : 1 Percentage of Occurrence of the Word Bill is : 7.14286% Occurrences of the Word Harry is : Harry : 1 Percentage of Occurrence of the Word Harry is : 7.14286% Occurrences of the Word Shawn is : Shawn : 1 Percentage of Occurrence of the Word Shawn is : 7.14286% Occurrences of the Word Perk is : Perk : 1 Percentage of Occurrence of the Word Perk is : 7.14286% Occurrences of the Word Cameroon is : Cameroon : 1 Percentage of Occurrence of the Word Cameroon is : 7.14286% Occurrences of the Word Bush is : Bush : 1 Percentage of Occurrence of the Word Bush is : 7.14286% Occurrences of the Word Moore is : Moore : 1 Percentage of Occurrence of the Word Moore is : 7.14286% Occurrences of the Word Mary is : Mary : 1 Percentage of Occurrence of the Word Mary is : 7.14286%
  • 6. Occurrences of the Word Marxter is : Marxter : 1 Percentage of Occurrence of the Word Marxter is : 7.14286% Number of Occurrences Found in the data read are : 1 The total Words in the file are : 14 Hope this is helpful.