SlideShare a Scribd company logo
1 of 12
Download to read offline
#include
#include
#include
#include
#include
using namespace std;
//Used from
int index_of_largest(const int array[], int startIndex, const int size);
void selectSort(int a[], const int size);
void swap(int& i1, int& it2);
void fileOption();
void inputOption();
void unique(const int inputArray[], int uniqueArray[], int countArray[], const int size);
void printFileScreen(const int uniqueArray[], const int countArray[], const int size);
int main()
{
// int size;
char userInput[5];
//
cout << "Read file from Input file? (Y/N) ";
cin >> userInput;
if(toupper(userInput[0]) == 'Y')
{
fileOption();
}
else
{
inputOption();
}
return 0;
}
void selectSort(int array[], const int size)
{
int smallestIndex;
for(int i = 0;i < size - 1;i++)
{
smallestIndex = index_of_largest(array , i , size);
swap(array[i] , array[smallestIndex]);
}
}
void swap(int& i1, int& i2)
{
int temp;
temp = i1;
i1 = i2;
i2 = temp;
}
int index_of_largest(const int array[], int startIndex, const int size)
{
int min = array[startIndex] , index_of_min = startIndex;
for(int i = startIndex + 1;i < size;i++)
if(array[i] > min)
{
min = array[i];
index_of_min = i;
}
return index_of_min;
}
void unique(const int inputArray[], int uniqueArray[], int countArray[], const int size)
{
int number;
int j = 0;
int index;
for(int i = 0;i < size;i++)
{
int flag = 0;
number = inputArray[i];
//for each element in inputArray, check if it is there in uniqueArray
for (int k = 0; k < j; ++k)
{
if(number == uniqueArray[k])
{
flag = 1;
index = k;
}
}
if(flag == 0)
{
//if so, increment the countArray by 1
countArray[j]++;
// copy the element to uniqueArray
uniqueArray[j] = number;
j++;
}
else
countArray[index]++;
}
}
void fileOption()
{
int inputArray[50];
int countArray[50] = {0};
int uniqueArray[50]= {0};
ifstream in_stream;
char fileName[16];
cout << "What file would you like to obtain input from? ";
cin >> fileName;
in_stream.open(fileName);
if(in_stream.fail())
{
cout << "Error: Could not open file!" << endl;
exit(1);
}
int size = 0;
while(in_stream >> inputArray[size])
{
size++;
}
selectSort(inputArray , size);
unique(inputArray , uniqueArray , countArray , size);
printFileScreen(uniqueArray , countArray , size);
}
void inputOption()
{
int inputArray[50];
int countArray[50] = {0};
int uniqueArray[50] = {0};
int size;
cout << "How many numbers would you like to enter? ";
cin >> size;
cout << "Enter numbers:" << endl;
for(int i = 0;i < size;i++)
{
cin >> inputArray[i];
}
selectSort(inputArray , size);
unique(inputArray , uniqueArray , countArray , size);
printFileScreen(uniqueArray , countArray , size);
}
void printFileScreen(const int uniqueArray[], const int countArray[], const int size)
{
//cout << "jaja";
ofstream output_file;
output_file.open("lab3Exercise2.txt");
if(output_file.fail())
{
cout << "Error: Could not open file!" << endl;
exit(1);
}
output_file << "Nt" << "count ";
for(int i = 0;i < size;i++)
{
if(uniqueArray[i] != 0)
{
output_file << uniqueArray[i] << "t";
output_file << countArray[i] << endl;
}
}
cout << "Nt" << "count ";
for(int i = 0;i < size;i++)
{
if(uniqueArray[i] != 0)
{
cout << uniqueArray[i] << "t";
cout << countArray[i] << endl;
}
}
}
/*
output:
1)
Read file from Input file? (Y/N) y
What file would you like to obtain input from? inputfile.txt
N count
4 2
3 1
1 2
-3 1
lab3Exercise2.txt
N count
4 2
3 1
1 2
-3 1
2)
Read file from Input file? (Y/N) n
How many numbers would you like to enter? 10
Enter numbers:
-1
3
4
2
3
4
6
7
6
4
N count
7 1
6 2
4 3
3 2
2 1
-1 1
lab3Exercise2.txt
N count
7 1
6 2
4 3
3 2
2 1
-1 1
*/
Solution
#include
#include
#include
#include
#include
using namespace std;
//Used from
int index_of_largest(const int array[], int startIndex, const int size);
void selectSort(int a[], const int size);
void swap(int& i1, int& it2);
void fileOption();
void inputOption();
void unique(const int inputArray[], int uniqueArray[], int countArray[], const int size);
void printFileScreen(const int uniqueArray[], const int countArray[], const int size);
int main()
{
// int size;
char userInput[5];
//
cout << "Read file from Input file? (Y/N) ";
cin >> userInput;
if(toupper(userInput[0]) == 'Y')
{
fileOption();
}
else
{
inputOption();
}
return 0;
}
void selectSort(int array[], const int size)
{
int smallestIndex;
for(int i = 0;i < size - 1;i++)
{
smallestIndex = index_of_largest(array , i , size);
swap(array[i] , array[smallestIndex]);
}
}
void swap(int& i1, int& i2)
{
int temp;
temp = i1;
i1 = i2;
i2 = temp;
}
int index_of_largest(const int array[], int startIndex, const int size)
{
int min = array[startIndex] , index_of_min = startIndex;
for(int i = startIndex + 1;i < size;i++)
if(array[i] > min)
{
min = array[i];
index_of_min = i;
}
return index_of_min;
}
void unique(const int inputArray[], int uniqueArray[], int countArray[], const int size)
{
int number;
int j = 0;
int index;
for(int i = 0;i < size;i++)
{
int flag = 0;
number = inputArray[i];
//for each element in inputArray, check if it is there in uniqueArray
for (int k = 0; k < j; ++k)
{
if(number == uniqueArray[k])
{
flag = 1;
index = k;
}
}
if(flag == 0)
{
//if so, increment the countArray by 1
countArray[j]++;
// copy the element to uniqueArray
uniqueArray[j] = number;
j++;
}
else
countArray[index]++;
}
}
void fileOption()
{
int inputArray[50];
int countArray[50] = {0};
int uniqueArray[50]= {0};
ifstream in_stream;
char fileName[16];
cout << "What file would you like to obtain input from? ";
cin >> fileName;
in_stream.open(fileName);
if(in_stream.fail())
{
cout << "Error: Could not open file!" << endl;
exit(1);
}
int size = 0;
while(in_stream >> inputArray[size])
{
size++;
}
selectSort(inputArray , size);
unique(inputArray , uniqueArray , countArray , size);
printFileScreen(uniqueArray , countArray , size);
}
void inputOption()
{
int inputArray[50];
int countArray[50] = {0};
int uniqueArray[50] = {0};
int size;
cout << "How many numbers would you like to enter? ";
cin >> size;
cout << "Enter numbers:" << endl;
for(int i = 0;i < size;i++)
{
cin >> inputArray[i];
}
selectSort(inputArray , size);
unique(inputArray , uniqueArray , countArray , size);
printFileScreen(uniqueArray , countArray , size);
}
void printFileScreen(const int uniqueArray[], const int countArray[], const int size)
{
//cout << "jaja";
ofstream output_file;
output_file.open("lab3Exercise2.txt");
if(output_file.fail())
{
cout << "Error: Could not open file!" << endl;
exit(1);
}
output_file << "Nt" << "count ";
for(int i = 0;i < size;i++)
{
if(uniqueArray[i] != 0)
{
output_file << uniqueArray[i] << "t";
output_file << countArray[i] << endl;
}
}
cout << "Nt" << "count ";
for(int i = 0;i < size;i++)
{
if(uniqueArray[i] != 0)
{
cout << uniqueArray[i] << "t";
cout << countArray[i] << endl;
}
}
}
/*
output:
1)
Read file from Input file? (Y/N) y
What file would you like to obtain input from? inputfile.txt
N count
4 2
3 1
1 2
-3 1
lab3Exercise2.txt
N count
4 2
3 1
1 2
-3 1
2)
Read file from Input file? (Y/N) n
How many numbers would you like to enter? 10
Enter numbers:
-1
3
4
2
3
4
6
7
6
4
N count
7 1
6 2
4 3
3 2
2 1
-1 1
lab3Exercise2.txt
N count
7 1
6 2
4 3
3 2
2 1
-1 1
*/

More Related Content

Similar to #include iostream #include fstream #include map #include.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.pdfarri2009av
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptxradhushri
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfRahul04August
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ applicationDaniele Pallastrelli
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semesterDOSONKA Group
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errorsPVS-Studio
 
#include #include #include using namespace std- class ErrorHandler(.docx
#include  #include  #include  using namespace std- class ErrorHandler(.docx#include  #include  #include  using namespace std- class ErrorHandler(.docx
#include #include #include using namespace std- class ErrorHandler(.docxloisj1
 
C programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdfC programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdfbadshetoms
 
Improving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinImproving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinIain Hull
 
I need to find run time analysis and description of the algo.pdf
I need to find run time analysis and description of the algo.pdfI need to find run time analysis and description of the algo.pdf
I need to find run time analysis and description of the algo.pdfaakashenterprises
 
ch9_additional.ppt
ch9_additional.pptch9_additional.ppt
ch9_additional.pptLokeshK66
 
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
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
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
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfshreeaadithyaacellso
 

Similar to #include iostream #include fstream #include map #include.pdf (20)

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
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
File Handling Program
File Handling ProgramFile Handling Program
File Handling Program
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errors
 
#include #include #include using namespace std- class ErrorHandler(.docx
#include  #include  #include  using namespace std- class ErrorHandler(.docx#include  #include  #include  using namespace std- class ErrorHandler(.docx
#include #include #include using namespace std- class ErrorHandler(.docx
 
C programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdfC programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdf
 
C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
 
Improving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinImproving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con Berlin
 
I need to find run time analysis and description of the algo.pdf
I need to find run time analysis and description of the algo.pdfI need to find run time analysis and description of the algo.pdf
I need to find run time analysis and description of the algo.pdf
 
ch9_additional.ppt
ch9_additional.pptch9_additional.ppt
ch9_additional.ppt
 
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
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
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
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 

More from inbox5

Use of the plates within a specific time is necessary as time of inc.pdf
Use of the plates within a specific time is necessary as time of inc.pdfUse of the plates within a specific time is necessary as time of inc.pdf
Use of the plates within a specific time is necessary as time of inc.pdfinbox5
 
The five terrestrial adaptations of the seed plants include, reducti.pdf
The five terrestrial adaptations of the seed plants include, reducti.pdfThe five terrestrial adaptations of the seed plants include, reducti.pdf
The five terrestrial adaptations of the seed plants include, reducti.pdfinbox5
 
SELF THEORY OF LATE ADULT HOOD it describes the changes of a adult.pdf
SELF THEORY OF LATE ADULT HOOD  it describes the changes of a adult.pdfSELF THEORY OF LATE ADULT HOOD  it describes the changes of a adult.pdf
SELF THEORY OF LATE ADULT HOOD it describes the changes of a adult.pdfinbox5
 
PV = PMTiThe goal is to solve the formula for i, doing so by isol.pdf
PV = PMTiThe goal is to solve the formula for i, doing so by isol.pdfPV = PMTiThe goal is to solve the formula for i, doing so by isol.pdf
PV = PMTiThe goal is to solve the formula for i, doing so by isol.pdfinbox5
 
Normal gene regulation in MAT locus YeastThere are 3 regulatory p.pdf
Normal gene regulation in MAT locus YeastThere are 3 regulatory p.pdfNormal gene regulation in MAT locus YeastThere are 3 regulatory p.pdf
Normal gene regulation in MAT locus YeastThere are 3 regulatory p.pdfinbox5
 
My answer 23SolutionMy answer 23.pdf
My answer 23SolutionMy answer 23.pdfMy answer 23SolutionMy answer 23.pdf
My answer 23SolutionMy answer 23.pdfinbox5
 
Ionic compounds have electropositive and electronegative elements pr.pdf
Ionic compounds have electropositive and electronegative elements pr.pdfIonic compounds have electropositive and electronegative elements pr.pdf
Ionic compounds have electropositive and electronegative elements pr.pdfinbox5
 
Grey matter in the spinal cord is known as the grey column which tra.pdf
Grey matter in the spinal cord is known as the grey column which tra.pdfGrey matter in the spinal cord is known as the grey column which tra.pdf
Grey matter in the spinal cord is known as the grey column which tra.pdfinbox5
 
DateDescriptionDebitCredit2014Jan. 4Delivery Truck2800.pdf
DateDescriptionDebitCredit2014Jan. 4Delivery Truck2800.pdfDateDescriptionDebitCredit2014Jan. 4Delivery Truck2800.pdf
DateDescriptionDebitCredit2014Jan. 4Delivery Truck2800.pdfinbox5
 
c. A destructor to free any allocated objects.d. A copy constructo.pdf
c. A destructor to free any allocated objects.d. A copy constructo.pdfc. A destructor to free any allocated objects.d. A copy constructo.pdf
c. A destructor to free any allocated objects.d. A copy constructo.pdfinbox5
 
Barrier to entryThe government intervention to the barriers to en.pdf
Barrier to entryThe government intervention to the barriers to en.pdfBarrier to entryThe government intervention to the barriers to en.pdf
Barrier to entryThe government intervention to the barriers to en.pdfinbox5
 
Answer D all of the aboveLipids like triglycerides are semi-solid.pdf
Answer D all of the aboveLipids like triglycerides are semi-solid.pdfAnswer D all of the aboveLipids like triglycerides are semi-solid.pdf
Answer D all of the aboveLipids like triglycerides are semi-solid.pdfinbox5
 
An example of when a one-way ANOVA could be used is if you want to d.pdf
An example of when a one-way ANOVA could be used is if you want to d.pdfAn example of when a one-way ANOVA could be used is if you want to d.pdf
An example of when a one-way ANOVA could be used is if you want to d.pdfinbox5
 
10.dry and hot conditions11.C4 plants12.bundle sheet cells14.p.pdf
10.dry and hot conditions11.C4 plants12.bundle sheet cells14.p.pdf10.dry and hot conditions11.C4 plants12.bundle sheet cells14.p.pdf
10.dry and hot conditions11.C4 plants12.bundle sheet cells14.p.pdfinbox5
 
1. Off Page refference arrow2. Connector Symbol3. Process4.Del.pdf
1. Off Page refference arrow2. Connector Symbol3. Process4.Del.pdf1. Off Page refference arrow2. Connector Symbol3. Process4.Del.pdf
1. Off Page refference arrow2. Connector Symbol3. Process4.Del.pdfinbox5
 
1) the values of potassium, chlorine and HCO3 values are abnormal an.pdf
1) the values of potassium, chlorine and HCO3 values are abnormal an.pdf1) the values of potassium, chlorine and HCO3 values are abnormal an.pdf
1) the values of potassium, chlorine and HCO3 values are abnormal an.pdfinbox5
 
The intermediate is the compound A. There are a c.pdf
                     The intermediate is the compound A. There are a c.pdf                     The intermediate is the compound A. There are a c.pdf
The intermediate is the compound A. There are a c.pdfinbox5
 
When ionic solids dissolve in water theions that are adjacent to each.pdf
 When ionic solids dissolve in water theions that are adjacent to each.pdf When ionic solids dissolve in water theions that are adjacent to each.pdf
When ionic solids dissolve in water theions that are adjacent to each.pdfinbox5
 
r=(13)d(I-)dt .pdf
                     r=(13)d(I-)dt                                  .pdf                     r=(13)d(I-)dt                                  .pdf
r=(13)d(I-)dt .pdfinbox5
 
on the phosphorus. Solution .pdf
                     on the phosphorus. Solution                  .pdf                     on the phosphorus. Solution                  .pdf
on the phosphorus. Solution .pdfinbox5
 

More from inbox5 (20)

Use of the plates within a specific time is necessary as time of inc.pdf
Use of the plates within a specific time is necessary as time of inc.pdfUse of the plates within a specific time is necessary as time of inc.pdf
Use of the plates within a specific time is necessary as time of inc.pdf
 
The five terrestrial adaptations of the seed plants include, reducti.pdf
The five terrestrial adaptations of the seed plants include, reducti.pdfThe five terrestrial adaptations of the seed plants include, reducti.pdf
The five terrestrial adaptations of the seed plants include, reducti.pdf
 
SELF THEORY OF LATE ADULT HOOD it describes the changes of a adult.pdf
SELF THEORY OF LATE ADULT HOOD  it describes the changes of a adult.pdfSELF THEORY OF LATE ADULT HOOD  it describes the changes of a adult.pdf
SELF THEORY OF LATE ADULT HOOD it describes the changes of a adult.pdf
 
PV = PMTiThe goal is to solve the formula for i, doing so by isol.pdf
PV = PMTiThe goal is to solve the formula for i, doing so by isol.pdfPV = PMTiThe goal is to solve the formula for i, doing so by isol.pdf
PV = PMTiThe goal is to solve the formula for i, doing so by isol.pdf
 
Normal gene regulation in MAT locus YeastThere are 3 regulatory p.pdf
Normal gene regulation in MAT locus YeastThere are 3 regulatory p.pdfNormal gene regulation in MAT locus YeastThere are 3 regulatory p.pdf
Normal gene regulation in MAT locus YeastThere are 3 regulatory p.pdf
 
My answer 23SolutionMy answer 23.pdf
My answer 23SolutionMy answer 23.pdfMy answer 23SolutionMy answer 23.pdf
My answer 23SolutionMy answer 23.pdf
 
Ionic compounds have electropositive and electronegative elements pr.pdf
Ionic compounds have electropositive and electronegative elements pr.pdfIonic compounds have electropositive and electronegative elements pr.pdf
Ionic compounds have electropositive and electronegative elements pr.pdf
 
Grey matter in the spinal cord is known as the grey column which tra.pdf
Grey matter in the spinal cord is known as the grey column which tra.pdfGrey matter in the spinal cord is known as the grey column which tra.pdf
Grey matter in the spinal cord is known as the grey column which tra.pdf
 
DateDescriptionDebitCredit2014Jan. 4Delivery Truck2800.pdf
DateDescriptionDebitCredit2014Jan. 4Delivery Truck2800.pdfDateDescriptionDebitCredit2014Jan. 4Delivery Truck2800.pdf
DateDescriptionDebitCredit2014Jan. 4Delivery Truck2800.pdf
 
c. A destructor to free any allocated objects.d. A copy constructo.pdf
c. A destructor to free any allocated objects.d. A copy constructo.pdfc. A destructor to free any allocated objects.d. A copy constructo.pdf
c. A destructor to free any allocated objects.d. A copy constructo.pdf
 
Barrier to entryThe government intervention to the barriers to en.pdf
Barrier to entryThe government intervention to the barriers to en.pdfBarrier to entryThe government intervention to the barriers to en.pdf
Barrier to entryThe government intervention to the barriers to en.pdf
 
Answer D all of the aboveLipids like triglycerides are semi-solid.pdf
Answer D all of the aboveLipids like triglycerides are semi-solid.pdfAnswer D all of the aboveLipids like triglycerides are semi-solid.pdf
Answer D all of the aboveLipids like triglycerides are semi-solid.pdf
 
An example of when a one-way ANOVA could be used is if you want to d.pdf
An example of when a one-way ANOVA could be used is if you want to d.pdfAn example of when a one-way ANOVA could be used is if you want to d.pdf
An example of when a one-way ANOVA could be used is if you want to d.pdf
 
10.dry and hot conditions11.C4 plants12.bundle sheet cells14.p.pdf
10.dry and hot conditions11.C4 plants12.bundle sheet cells14.p.pdf10.dry and hot conditions11.C4 plants12.bundle sheet cells14.p.pdf
10.dry and hot conditions11.C4 plants12.bundle sheet cells14.p.pdf
 
1. Off Page refference arrow2. Connector Symbol3. Process4.Del.pdf
1. Off Page refference arrow2. Connector Symbol3. Process4.Del.pdf1. Off Page refference arrow2. Connector Symbol3. Process4.Del.pdf
1. Off Page refference arrow2. Connector Symbol3. Process4.Del.pdf
 
1) the values of potassium, chlorine and HCO3 values are abnormal an.pdf
1) the values of potassium, chlorine and HCO3 values are abnormal an.pdf1) the values of potassium, chlorine and HCO3 values are abnormal an.pdf
1) the values of potassium, chlorine and HCO3 values are abnormal an.pdf
 
The intermediate is the compound A. There are a c.pdf
                     The intermediate is the compound A. There are a c.pdf                     The intermediate is the compound A. There are a c.pdf
The intermediate is the compound A. There are a c.pdf
 
When ionic solids dissolve in water theions that are adjacent to each.pdf
 When ionic solids dissolve in water theions that are adjacent to each.pdf When ionic solids dissolve in water theions that are adjacent to each.pdf
When ionic solids dissolve in water theions that are adjacent to each.pdf
 
r=(13)d(I-)dt .pdf
                     r=(13)d(I-)dt                                  .pdf                     r=(13)d(I-)dt                                  .pdf
r=(13)d(I-)dt .pdf
 
on the phosphorus. Solution .pdf
                     on the phosphorus. Solution                  .pdf                     on the phosphorus. Solution                  .pdf
on the phosphorus. Solution .pdf
 

Recently uploaded

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
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)Jisc
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
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
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
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...Pooja Bhuva
 
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 FellowsMebane Rash
 
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).pptxmarlenawright1
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 

Recently uploaded (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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)
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
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
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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...
 
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
 
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
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

#include iostream #include fstream #include map #include.pdf

  • 1. #include #include #include #include #include using namespace std; //Used from int index_of_largest(const int array[], int startIndex, const int size); void selectSort(int a[], const int size); void swap(int& i1, int& it2); void fileOption(); void inputOption(); void unique(const int inputArray[], int uniqueArray[], int countArray[], const int size); void printFileScreen(const int uniqueArray[], const int countArray[], const int size); int main() { // int size; char userInput[5]; // cout << "Read file from Input file? (Y/N) "; cin >> userInput; if(toupper(userInput[0]) == 'Y') { fileOption(); } else { inputOption(); } return 0; } void selectSort(int array[], const int size) { int smallestIndex; for(int i = 0;i < size - 1;i++)
  • 2. { smallestIndex = index_of_largest(array , i , size); swap(array[i] , array[smallestIndex]); } } void swap(int& i1, int& i2) { int temp; temp = i1; i1 = i2; i2 = temp; } int index_of_largest(const int array[], int startIndex, const int size) { int min = array[startIndex] , index_of_min = startIndex; for(int i = startIndex + 1;i < size;i++) if(array[i] > min) { min = array[i]; index_of_min = i; } return index_of_min; } void unique(const int inputArray[], int uniqueArray[], int countArray[], const int size) { int number; int j = 0; int index; for(int i = 0;i < size;i++) { int flag = 0; number = inputArray[i]; //for each element in inputArray, check if it is there in uniqueArray for (int k = 0; k < j; ++k) { if(number == uniqueArray[k])
  • 3. { flag = 1; index = k; } } if(flag == 0) { //if so, increment the countArray by 1 countArray[j]++; // copy the element to uniqueArray uniqueArray[j] = number; j++; } else countArray[index]++; } } void fileOption() { int inputArray[50]; int countArray[50] = {0}; int uniqueArray[50]= {0}; ifstream in_stream; char fileName[16]; cout << "What file would you like to obtain input from? "; cin >> fileName; in_stream.open(fileName); if(in_stream.fail()) { cout << "Error: Could not open file!" << endl; exit(1); } int size = 0; while(in_stream >> inputArray[size]) {
  • 4. size++; } selectSort(inputArray , size); unique(inputArray , uniqueArray , countArray , size); printFileScreen(uniqueArray , countArray , size); } void inputOption() { int inputArray[50]; int countArray[50] = {0}; int uniqueArray[50] = {0}; int size; cout << "How many numbers would you like to enter? "; cin >> size; cout << "Enter numbers:" << endl; for(int i = 0;i < size;i++) { cin >> inputArray[i]; } selectSort(inputArray , size); unique(inputArray , uniqueArray , countArray , size); printFileScreen(uniqueArray , countArray , size); } void printFileScreen(const int uniqueArray[], const int countArray[], const int size) { //cout << "jaja"; ofstream output_file; output_file.open("lab3Exercise2.txt"); if(output_file.fail()) { cout << "Error: Could not open file!" << endl; exit(1); } output_file << "Nt" << "count "; for(int i = 0;i < size;i++) {
  • 5. if(uniqueArray[i] != 0) { output_file << uniqueArray[i] << "t"; output_file << countArray[i] << endl; } } cout << "Nt" << "count "; for(int i = 0;i < size;i++) { if(uniqueArray[i] != 0) { cout << uniqueArray[i] << "t"; cout << countArray[i] << endl; } } } /* output: 1) Read file from Input file? (Y/N) y What file would you like to obtain input from? inputfile.txt N count 4 2 3 1 1 2 -3 1 lab3Exercise2.txt N count 4 2 3 1 1 2 -3 1 2) Read file from Input file? (Y/N) n
  • 6. How many numbers would you like to enter? 10 Enter numbers: -1 3 4 2 3 4 6 7 6 4 N count 7 1 6 2 4 3 3 2 2 1 -1 1 lab3Exercise2.txt N count 7 1 6 2 4 3 3 2 2 1 -1 1 */ Solution #include #include #include
  • 7. #include #include using namespace std; //Used from int index_of_largest(const int array[], int startIndex, const int size); void selectSort(int a[], const int size); void swap(int& i1, int& it2); void fileOption(); void inputOption(); void unique(const int inputArray[], int uniqueArray[], int countArray[], const int size); void printFileScreen(const int uniqueArray[], const int countArray[], const int size); int main() { // int size; char userInput[5]; // cout << "Read file from Input file? (Y/N) "; cin >> userInput; if(toupper(userInput[0]) == 'Y') { fileOption(); } else { inputOption(); } return 0; } void selectSort(int array[], const int size) { int smallestIndex; for(int i = 0;i < size - 1;i++) { smallestIndex = index_of_largest(array , i , size); swap(array[i] , array[smallestIndex]); }
  • 8. } void swap(int& i1, int& i2) { int temp; temp = i1; i1 = i2; i2 = temp; } int index_of_largest(const int array[], int startIndex, const int size) { int min = array[startIndex] , index_of_min = startIndex; for(int i = startIndex + 1;i < size;i++) if(array[i] > min) { min = array[i]; index_of_min = i; } return index_of_min; } void unique(const int inputArray[], int uniqueArray[], int countArray[], const int size) { int number; int j = 0; int index; for(int i = 0;i < size;i++) { int flag = 0; number = inputArray[i]; //for each element in inputArray, check if it is there in uniqueArray for (int k = 0; k < j; ++k) { if(number == uniqueArray[k]) { flag = 1; index = k; }
  • 9. } if(flag == 0) { //if so, increment the countArray by 1 countArray[j]++; // copy the element to uniqueArray uniqueArray[j] = number; j++; } else countArray[index]++; } } void fileOption() { int inputArray[50]; int countArray[50] = {0}; int uniqueArray[50]= {0}; ifstream in_stream; char fileName[16]; cout << "What file would you like to obtain input from? "; cin >> fileName; in_stream.open(fileName); if(in_stream.fail()) { cout << "Error: Could not open file!" << endl; exit(1); } int size = 0; while(in_stream >> inputArray[size]) { size++; } selectSort(inputArray , size); unique(inputArray , uniqueArray , countArray , size);
  • 10. printFileScreen(uniqueArray , countArray , size); } void inputOption() { int inputArray[50]; int countArray[50] = {0}; int uniqueArray[50] = {0}; int size; cout << "How many numbers would you like to enter? "; cin >> size; cout << "Enter numbers:" << endl; for(int i = 0;i < size;i++) { cin >> inputArray[i]; } selectSort(inputArray , size); unique(inputArray , uniqueArray , countArray , size); printFileScreen(uniqueArray , countArray , size); } void printFileScreen(const int uniqueArray[], const int countArray[], const int size) { //cout << "jaja"; ofstream output_file; output_file.open("lab3Exercise2.txt"); if(output_file.fail()) { cout << "Error: Could not open file!" << endl; exit(1); } output_file << "Nt" << "count "; for(int i = 0;i < size;i++) { if(uniqueArray[i] != 0) { output_file << uniqueArray[i] << "t"; output_file << countArray[i] << endl;
  • 11. } } cout << "Nt" << "count "; for(int i = 0;i < size;i++) { if(uniqueArray[i] != 0) { cout << uniqueArray[i] << "t"; cout << countArray[i] << endl; } } } /* output: 1) Read file from Input file? (Y/N) y What file would you like to obtain input from? inputfile.txt N count 4 2 3 1 1 2 -3 1 lab3Exercise2.txt N count 4 2 3 1 1 2 -3 1 2) Read file from Input file? (Y/N) n How many numbers would you like to enter? 10 Enter numbers: -1 3
  • 12. 4 2 3 4 6 7 6 4 N count 7 1 6 2 4 3 3 2 2 1 -1 1 lab3Exercise2.txt N count 7 1 6 2 4 3 3 2 2 1 -1 1 */