SlideShare a Scribd company logo
#include
#include //Might end up not being used
#include
using namespace std;
void CopyString (char string1[24], char string2[24]);
int main ()
{
int doDebug = 0;
cout << "Do Debug Output? [Y/N]:";
char response;
cin >> response;
if (response == 'y' || response == 'Y')
{
doDebug = 1;
}
int nameAmount;
char inputFileName[50];
cout << "Input the name of the file to be read (Include the extension, ";
cout << "must be less than 48 characters): ";
cin >> inputFileName;
inputFileName[49] = '0'; //To ensure null terminator
cout << "Input the number of names: ";
cin >> nameAmount;
char namesUnsorted[nameAmount][24];
char namesSorted[nameAmount][24];
ifstream inputFile;
inputFile.open(inputFileName);
for (int i = 0; i < nameAmount; i++)
{
inputFile.getline(namesUnsorted[i], 24, ' ');
namesUnsorted[i][23] = '0';
}
inputFile.close();
cout << "Found the following entries in " << inputFileName << ":" << endl;
for (int i = 0; i < nameAmount; i++)
{
cout << namesUnsorted[i] << endl;
}
//Debug
if (doDebug)
{
cout << "The following chars were found in entry 3: " << endl;
for (int i = 0; namesUnsorted[3][i] != '0'; i++)
{
cout << "'" << namesUnsorted[3][i] << "'" << endl;
}
}
//Char values A-Z = [65, 90], a-z = [97, 122]
//To go from lower to upper, subtract 32
//To keep track of which position is next in the sorted array
int onName = 0;
//Begin main sorting algorithm
//Go through every letter
for (char thisLetter = 'A'; thisLetter <= 'Z'; thisLetter++)
{
//Go through every name in the unsorted array
for (int i = 0; i < nameAmount; i++)
{
//If a match is found
if (namesUnsorted[i][0] == thisLetter)
{
//If there is already a name entered before and it starts with
//the same letter as the match found
if ((onName > 0) && (namesSorted[(onName - 1)][0] == thisLetter))
{
cout << "Comparing " << namesSorted[(onName - 1)] << namesUnsorted[i] <<
endl;
//Go through every letter to find which is lower
for (int checkChar = 0; checkChar < 24; checkChar++)
{
char sortedChar, unsortedChar;
sortedChar = namesSorted[onName - 1][checkChar];
unsortedChar = namesUnsorted[i][checkChar];
//If the char is a lowercase letter, convert to
//uppercase
if (sortedChar > 'Z')
{
sortedChar -= 32;
}
if (unsortedChar > 'Z')
{
unsortedChar -= 32;
}
//The sorted name ended sooner
if (sortedChar == '0' && unsortedChar != '0')
{
//namesSorted[onName - 1][checkChar] = '0';
//Keep the sorted name where it is and place the
//unsorted name in the entry below
CopyString(namesUnsorted[i], namesSorted[onName]);
break;
} else if (unsortedChar == '0' && sortedChar != '0')
{
//The unsorted name ended sooner
//namesUnsorted[i][checkChar] = '0';
//Move the sorted name down one and place the
//unsorted name to where the sorted one was
CopyString(namesSorted[(onName - 1)], namesSorted[onName]);
CopyString(namesUnsorted[i], namesSorted[(onName - 1)]);
break;
}
//Debug
if (doDebug)
{
cout << "S: " << sortedChar << " | U: " << unsortedChar << endl;
}
if (sortedChar > unsortedChar) //Sorted is higher
{
//Move the sorted name down one and place the
//unsorted name to where the sorted one was
CopyString(namesSorted[(onName - 1)], namesSorted[onName]);
CopyString(namesUnsorted[i], namesSorted[(onName - 1)]);
break;
} else if (sortedChar < unsortedChar)
{
//Keep the sorted name where it is and place the
//unsorted name in the entry below
CopyString(namesUnsorted[i], namesSorted[onName]);
}
//If it's checking the final char and no match has
//been found, they must be the same
if (checkChar == 23)
{
CopyString(namesUnsorted[i], namesSorted[onName]);
}
}
} else
{
CopyString(namesUnsorted[i], namesSorted[onName]);
}
onName++;
}
}
}
cout << endl << "Sorted names: " << endl;
for (int i = 0; i < nameAmount; i++)
{
cout << namesSorted[i] << endl;
}
char outputFileName[50];
cout << "Enter output file name (including extension): ";
cin >> outputFileName;
outputFileName[49] = '0';
ofstream outputFile;
outputFile.open(outputFileName);
for (int i = 0; i < nameAmount; i++)
{
outputFile << namesSorted[i] << " ";
}
outputFile.close();
cout << "Sorted list successfully stored in " << outputFileName << endl;
return 0;
}
void CopyString (char string1[24], char string2[24])
{
for (int i = 0; i < 24; i++)
{
string2[i] = string1[i];
}
string2[23] = '0';
return;
}
input.txt
Milda
Dan
Dale
Letha
Kurt
Daniel
Kandy
Tammy
Malisa
Corey
output.txt
Corey
Dale
Dan
Daniel
Kandy
Kurt
Letha
Malisa
Milda
Tammy
Solution
#include
#include //Might end up not being used
#include
using namespace std;
void CopyString (char string1[24], char string2[24]);
int main ()
{
int doDebug = 0;
cout << "Do Debug Output? [Y/N]:";
char response;
cin >> response;
if (response == 'y' || response == 'Y')
{
doDebug = 1;
}
int nameAmount;
char inputFileName[50];
cout << "Input the name of the file to be read (Include the extension, ";
cout << "must be less than 48 characters): ";
cin >> inputFileName;
inputFileName[49] = '0'; //To ensure null terminator
cout << "Input the number of names: ";
cin >> nameAmount;
char namesUnsorted[nameAmount][24];
char namesSorted[nameAmount][24];
ifstream inputFile;
inputFile.open(inputFileName);
for (int i = 0; i < nameAmount; i++)
{
inputFile.getline(namesUnsorted[i], 24, ' ');
namesUnsorted[i][23] = '0';
}
inputFile.close();
cout << "Found the following entries in " << inputFileName << ":" << endl;
for (int i = 0; i < nameAmount; i++)
{
cout << namesUnsorted[i] << endl;
}
//Debug
if (doDebug)
{
cout << "The following chars were found in entry 3: " << endl;
for (int i = 0; namesUnsorted[3][i] != '0'; i++)
{
cout << "'" << namesUnsorted[3][i] << "'" << endl;
}
}
//Char values A-Z = [65, 90], a-z = [97, 122]
//To go from lower to upper, subtract 32
//To keep track of which position is next in the sorted array
int onName = 0;
//Begin main sorting algorithm
//Go through every letter
for (char thisLetter = 'A'; thisLetter <= 'Z'; thisLetter++)
{
//Go through every name in the unsorted array
for (int i = 0; i < nameAmount; i++)
{
//If a match is found
if (namesUnsorted[i][0] == thisLetter)
{
//If there is already a name entered before and it starts with
//the same letter as the match found
if ((onName > 0) && (namesSorted[(onName - 1)][0] == thisLetter))
{
cout << "Comparing " << namesSorted[(onName - 1)] << namesUnsorted[i] <<
endl;
//Go through every letter to find which is lower
for (int checkChar = 0; checkChar < 24; checkChar++)
{
char sortedChar, unsortedChar;
sortedChar = namesSorted[onName - 1][checkChar];
unsortedChar = namesUnsorted[i][checkChar];
//If the char is a lowercase letter, convert to
//uppercase
if (sortedChar > 'Z')
{
sortedChar -= 32;
}
if (unsortedChar > 'Z')
{
unsortedChar -= 32;
}
//The sorted name ended sooner
if (sortedChar == '0' && unsortedChar != '0')
{
//namesSorted[onName - 1][checkChar] = '0';
//Keep the sorted name where it is and place the
//unsorted name in the entry below
CopyString(namesUnsorted[i], namesSorted[onName]);
break;
} else if (unsortedChar == '0' && sortedChar != '0')
{
//The unsorted name ended sooner
//namesUnsorted[i][checkChar] = '0';
//Move the sorted name down one and place the
//unsorted name to where the sorted one was
CopyString(namesSorted[(onName - 1)], namesSorted[onName]);
CopyString(namesUnsorted[i], namesSorted[(onName - 1)]);
break;
}
//Debug
if (doDebug)
{
cout << "S: " << sortedChar << " | U: " << unsortedChar << endl;
}
if (sortedChar > unsortedChar) //Sorted is higher
{
//Move the sorted name down one and place the
//unsorted name to where the sorted one was
CopyString(namesSorted[(onName - 1)], namesSorted[onName]);
CopyString(namesUnsorted[i], namesSorted[(onName - 1)]);
break;
} else if (sortedChar < unsortedChar)
{
//Keep the sorted name where it is and place the
//unsorted name in the entry below
CopyString(namesUnsorted[i], namesSorted[onName]);
}
//If it's checking the final char and no match has
//been found, they must be the same
if (checkChar == 23)
{
CopyString(namesUnsorted[i], namesSorted[onName]);
}
}
} else
{
CopyString(namesUnsorted[i], namesSorted[onName]);
}
onName++;
}
}
}
cout << endl << "Sorted names: " << endl;
for (int i = 0; i < nameAmount; i++)
{
cout << namesSorted[i] << endl;
}
char outputFileName[50];
cout << "Enter output file name (including extension): ";
cin >> outputFileName;
outputFileName[49] = '0';
ofstream outputFile;
outputFile.open(outputFileName);
for (int i = 0; i < nameAmount; i++)
{
outputFile << namesSorted[i] << " ";
}
outputFile.close();
cout << "Sorted list successfully stored in " << outputFileName << endl;
return 0;
}
void CopyString (char string1[24], char string2[24])
{
for (int i = 0; i < 24; i++)
{
string2[i] = string1[i];
}
string2[23] = '0';
return;
}
input.txt
Milda
Dan
Dale
Letha
Kurt
Daniel
Kandy
Tammy
Malisa
Corey
output.txt
Corey
Dale
Dan
Daniel
Kandy
Kurt
Letha
Malisa
Milda
Tammy

More Related Content

Similar to #include iostream #include iomanip Might end up not being.pdf

For C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdfFor C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdf
fathimafancyjeweller
 
SPL 13 | Character Array(String) in C
SPL 13 | Character Array(String) in CSPL 13 | Character Array(String) in C
SPL 13 | Character Array(String) in C
Mohammad Imam Hossain
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
Nooryaseen9
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
herminaherman
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
apleather
 
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdfHello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
amittripathi2002
 
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
ezonesolutions
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
arishmarketing21
 
Clean code
Clean codeClean code
Clean code
Arturo Herrero
 
Php functions
Php functionsPhp functions
Php functions
JIGAR MAKHIJA
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdf
jillisacebi75827
 
Structured data type
Structured data typeStructured data type
Structured data type
Omkar Majukar
 
week-7x
week-7xweek-7x
Data structure
Data structureData structure
Data structure
Markustec
 

Similar to #include iostream #include iomanip Might end up not being.pdf (14)

For C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdfFor C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdf
 
SPL 13 | Character Array(String) in C
SPL 13 | Character Array(String) in CSPL 13 | Character Array(String) in C
SPL 13 | Character Array(String) in C
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
 
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdfHello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
 
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
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
 
Clean code
Clean codeClean code
Clean code
 
Php functions
Php functionsPhp functions
Php functions
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdf
 
Structured data type
Structured data typeStructured data type
Structured data type
 
week-7x
week-7xweek-7x
week-7x
 
Data structure
Data structureData structure
Data structure
 

More from anandf0099

Riboflavin is required in the conversion of carbo.pdf
                     Riboflavin is required in the conversion of carbo.pdf                     Riboflavin is required in the conversion of carbo.pdf
Riboflavin is required in the conversion of carbo.pdf
anandf0099
 
PbS,Ag2O and CaSO4 are stable as they are insolub.pdf
                     PbS,Ag2O and CaSO4 are stable as they are insolub.pdf                     PbS,Ag2O and CaSO4 are stable as they are insolub.pdf
PbS,Ag2O and CaSO4 are stable as they are insolub.pdf
anandf0099
 
Optio D is the correct one. .pdf
                     Optio D is the correct one.                      .pdf                     Optio D is the correct one.                      .pdf
Optio D is the correct one. .pdf
anandf0099
 
Image not seenfound .pdf
                     Image not seenfound                             .pdf                     Image not seenfound                             .pdf
Image not seenfound .pdf
anandf0099
 
If multiple orbitals of the same energy are avail.pdf
                     If multiple orbitals of the same energy are avail.pdf                     If multiple orbitals of the same energy are avail.pdf
If multiple orbitals of the same energy are avail.pdf
anandf0099
 
What is a Distributed System Compare it with a computer network sys.pdf
What is a Distributed System Compare it with a computer network sys.pdfWhat is a Distributed System Compare it with a computer network sys.pdf
What is a Distributed System Compare it with a computer network sys.pdf
anandf0099
 
USES OF FINANCIAL STATEMENT ANALYSISFINANCIAL STATEMENT ANALYSIS .pdf
USES OF FINANCIAL STATEMENT ANALYSISFINANCIAL STATEMENT ANALYSIS .pdfUSES OF FINANCIAL STATEMENT ANALYSISFINANCIAL STATEMENT ANALYSIS .pdf
USES OF FINANCIAL STATEMENT ANALYSISFINANCIAL STATEMENT ANALYSIS .pdf
anandf0099
 
The movement of watersolvent across the osmotic gradient takes plac.pdf
The movement of watersolvent across the osmotic gradient takes plac.pdfThe movement of watersolvent across the osmotic gradient takes plac.pdf
The movement of watersolvent across the osmotic gradient takes plac.pdf
anandf0099
 
These groups are closely related not only is SO(2) a subgroup of O(.pdf
These groups are closely related not only is SO(2) a subgroup of O(.pdfThese groups are closely related not only is SO(2) a subgroup of O(.pdf
These groups are closely related not only is SO(2) a subgroup of O(.pdf
anandf0099
 
The probability of atom has zero quanta of energy is      P=Number.pdf
The probability of atom has zero quanta of energy is      P=Number.pdfThe probability of atom has zero quanta of energy is      P=Number.pdf
The probability of atom has zero quanta of energy is      P=Number.pdf
anandf0099
 
Copper turns green because it oxidizes. Coppe.pdf
                     Copper turns green because it oxidizes. Coppe.pdf                     Copper turns green because it oxidizes. Coppe.pdf
Copper turns green because it oxidizes. Coppe.pdf
anandf0099
 
CO2 and NO2 are acidic oxides as non-metal form a.pdf
                     CO2 and NO2 are acidic oxides as non-metal form a.pdf                     CO2 and NO2 are acidic oxides as non-metal form a.pdf
CO2 and NO2 are acidic oxides as non-metal form a.pdf
anandf0099
 
Ques-1 Development of tube feet of CRINOIDEADevelopment of tube f.pdf
Ques-1 Development of tube feet of CRINOIDEADevelopment of tube f.pdfQues-1 Development of tube feet of CRINOIDEADevelopment of tube f.pdf
Ques-1 Development of tube feet of CRINOIDEADevelopment of tube f.pdf
anandf0099
 
Program.csusing System; using System.Collections.Generic; usin.pdf
Program.csusing System; using System.Collections.Generic; usin.pdfProgram.csusing System; using System.Collections.Generic; usin.pdf
Program.csusing System; using System.Collections.Generic; usin.pdf
anandf0099
 
package chegg;import java.util.ArrayList; import java.util.List;.pdf
package chegg;import java.util.ArrayList; import java.util.List;.pdfpackage chegg;import java.util.ArrayList; import java.util.List;.pdf
package chegg;import java.util.ArrayList; import java.util.List;.pdf
anandf0099
 
B. propene. Solution B. p.pdf
                     B. propene. Solution                     B. p.pdf                     B. propene. Solution                     B. p.pdf
B. propene. Solution B. p.pdf
anandf0099
 
L{e^{-t}} = int _0 to infinty [e^{st}e^{2-t} dt = int _0 to infinty.pdf
L{e^{-t}} = int _0 to infinty [e^{st}e^{2-t} dt = int _0 to infinty.pdfL{e^{-t}} = int _0 to infinty [e^{st}e^{2-t} dt = int _0 to infinty.pdf
L{e^{-t}} = int _0 to infinty [e^{st}e^{2-t} dt = int _0 to infinty.pdf
anandf0099
 
Issue of Equity or Debt are commonly used methods for business finan.pdf
Issue of Equity or Debt are commonly used methods for business finan.pdfIssue of Equity or Debt are commonly used methods for business finan.pdf
Issue of Equity or Debt are commonly used methods for business finan.pdf
anandf0099
 
In probability we have two types of eventsIndependent Events who.pdf
In probability we have two types of eventsIndependent Events who.pdfIn probability we have two types of eventsIndependent Events who.pdf
In probability we have two types of eventsIndependent Events who.pdf
anandf0099
 
i have written ths code as per your requirements with clear comments.pdf
i have written ths code as per your requirements with clear comments.pdfi have written ths code as per your requirements with clear comments.pdf
i have written ths code as per your requirements with clear comments.pdf
anandf0099
 

More from anandf0099 (20)

Riboflavin is required in the conversion of carbo.pdf
                     Riboflavin is required in the conversion of carbo.pdf                     Riboflavin is required in the conversion of carbo.pdf
Riboflavin is required in the conversion of carbo.pdf
 
PbS,Ag2O and CaSO4 are stable as they are insolub.pdf
                     PbS,Ag2O and CaSO4 are stable as they are insolub.pdf                     PbS,Ag2O and CaSO4 are stable as they are insolub.pdf
PbS,Ag2O and CaSO4 are stable as they are insolub.pdf
 
Optio D is the correct one. .pdf
                     Optio D is the correct one.                      .pdf                     Optio D is the correct one.                      .pdf
Optio D is the correct one. .pdf
 
Image not seenfound .pdf
                     Image not seenfound                             .pdf                     Image not seenfound                             .pdf
Image not seenfound .pdf
 
If multiple orbitals of the same energy are avail.pdf
                     If multiple orbitals of the same energy are avail.pdf                     If multiple orbitals of the same energy are avail.pdf
If multiple orbitals of the same energy are avail.pdf
 
What is a Distributed System Compare it with a computer network sys.pdf
What is a Distributed System Compare it with a computer network sys.pdfWhat is a Distributed System Compare it with a computer network sys.pdf
What is a Distributed System Compare it with a computer network sys.pdf
 
USES OF FINANCIAL STATEMENT ANALYSISFINANCIAL STATEMENT ANALYSIS .pdf
USES OF FINANCIAL STATEMENT ANALYSISFINANCIAL STATEMENT ANALYSIS .pdfUSES OF FINANCIAL STATEMENT ANALYSISFINANCIAL STATEMENT ANALYSIS .pdf
USES OF FINANCIAL STATEMENT ANALYSISFINANCIAL STATEMENT ANALYSIS .pdf
 
The movement of watersolvent across the osmotic gradient takes plac.pdf
The movement of watersolvent across the osmotic gradient takes plac.pdfThe movement of watersolvent across the osmotic gradient takes plac.pdf
The movement of watersolvent across the osmotic gradient takes plac.pdf
 
These groups are closely related not only is SO(2) a subgroup of O(.pdf
These groups are closely related not only is SO(2) a subgroup of O(.pdfThese groups are closely related not only is SO(2) a subgroup of O(.pdf
These groups are closely related not only is SO(2) a subgroup of O(.pdf
 
The probability of atom has zero quanta of energy is      P=Number.pdf
The probability of atom has zero quanta of energy is      P=Number.pdfThe probability of atom has zero quanta of energy is      P=Number.pdf
The probability of atom has zero quanta of energy is      P=Number.pdf
 
Copper turns green because it oxidizes. Coppe.pdf
                     Copper turns green because it oxidizes. Coppe.pdf                     Copper turns green because it oxidizes. Coppe.pdf
Copper turns green because it oxidizes. Coppe.pdf
 
CO2 and NO2 are acidic oxides as non-metal form a.pdf
                     CO2 and NO2 are acidic oxides as non-metal form a.pdf                     CO2 and NO2 are acidic oxides as non-metal form a.pdf
CO2 and NO2 are acidic oxides as non-metal form a.pdf
 
Ques-1 Development of tube feet of CRINOIDEADevelopment of tube f.pdf
Ques-1 Development of tube feet of CRINOIDEADevelopment of tube f.pdfQues-1 Development of tube feet of CRINOIDEADevelopment of tube f.pdf
Ques-1 Development of tube feet of CRINOIDEADevelopment of tube f.pdf
 
Program.csusing System; using System.Collections.Generic; usin.pdf
Program.csusing System; using System.Collections.Generic; usin.pdfProgram.csusing System; using System.Collections.Generic; usin.pdf
Program.csusing System; using System.Collections.Generic; usin.pdf
 
package chegg;import java.util.ArrayList; import java.util.List;.pdf
package chegg;import java.util.ArrayList; import java.util.List;.pdfpackage chegg;import java.util.ArrayList; import java.util.List;.pdf
package chegg;import java.util.ArrayList; import java.util.List;.pdf
 
B. propene. Solution B. p.pdf
                     B. propene. Solution                     B. p.pdf                     B. propene. Solution                     B. p.pdf
B. propene. Solution B. p.pdf
 
L{e^{-t}} = int _0 to infinty [e^{st}e^{2-t} dt = int _0 to infinty.pdf
L{e^{-t}} = int _0 to infinty [e^{st}e^{2-t} dt = int _0 to infinty.pdfL{e^{-t}} = int _0 to infinty [e^{st}e^{2-t} dt = int _0 to infinty.pdf
L{e^{-t}} = int _0 to infinty [e^{st}e^{2-t} dt = int _0 to infinty.pdf
 
Issue of Equity or Debt are commonly used methods for business finan.pdf
Issue of Equity or Debt are commonly used methods for business finan.pdfIssue of Equity or Debt are commonly used methods for business finan.pdf
Issue of Equity or Debt are commonly used methods for business finan.pdf
 
In probability we have two types of eventsIndependent Events who.pdf
In probability we have two types of eventsIndependent Events who.pdfIn probability we have two types of eventsIndependent Events who.pdf
In probability we have two types of eventsIndependent Events who.pdf
 
i have written ths code as per your requirements with clear comments.pdf
i have written ths code as per your requirements with clear comments.pdfi have written ths code as per your requirements with clear comments.pdf
i have written ths code as per your requirements with clear comments.pdf
 

Recently uploaded

clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 

#include iostream #include iomanip Might end up not being.pdf

  • 1. #include #include //Might end up not being used #include using namespace std; void CopyString (char string1[24], char string2[24]); int main () { int doDebug = 0; cout << "Do Debug Output? [Y/N]:"; char response; cin >> response; if (response == 'y' || response == 'Y') { doDebug = 1; } int nameAmount; char inputFileName[50]; cout << "Input the name of the file to be read (Include the extension, "; cout << "must be less than 48 characters): "; cin >> inputFileName; inputFileName[49] = '0'; //To ensure null terminator cout << "Input the number of names: ";
  • 2. cin >> nameAmount; char namesUnsorted[nameAmount][24]; char namesSorted[nameAmount][24]; ifstream inputFile; inputFile.open(inputFileName); for (int i = 0; i < nameAmount; i++) { inputFile.getline(namesUnsorted[i], 24, ' '); namesUnsorted[i][23] = '0'; } inputFile.close(); cout << "Found the following entries in " << inputFileName << ":" << endl; for (int i = 0; i < nameAmount; i++) { cout << namesUnsorted[i] << endl; } //Debug if (doDebug) { cout << "The following chars were found in entry 3: " << endl; for (int i = 0; namesUnsorted[3][i] != '0'; i++) {
  • 3. cout << "'" << namesUnsorted[3][i] << "'" << endl; } } //Char values A-Z = [65, 90], a-z = [97, 122] //To go from lower to upper, subtract 32 //To keep track of which position is next in the sorted array int onName = 0; //Begin main sorting algorithm //Go through every letter for (char thisLetter = 'A'; thisLetter <= 'Z'; thisLetter++) { //Go through every name in the unsorted array for (int i = 0; i < nameAmount; i++) { //If a match is found if (namesUnsorted[i][0] == thisLetter) { //If there is already a name entered before and it starts with //the same letter as the match found if ((onName > 0) && (namesSorted[(onName - 1)][0] == thisLetter)) { cout << "Comparing " << namesSorted[(onName - 1)] << namesUnsorted[i] << endl; //Go through every letter to find which is lower for (int checkChar = 0; checkChar < 24; checkChar++) { char sortedChar, unsortedChar; sortedChar = namesSorted[onName - 1][checkChar]; unsortedChar = namesUnsorted[i][checkChar]; //If the char is a lowercase letter, convert to
  • 4. //uppercase if (sortedChar > 'Z') { sortedChar -= 32; } if (unsortedChar > 'Z') { unsortedChar -= 32; } //The sorted name ended sooner if (sortedChar == '0' && unsortedChar != '0') { //namesSorted[onName - 1][checkChar] = '0'; //Keep the sorted name where it is and place the //unsorted name in the entry below CopyString(namesUnsorted[i], namesSorted[onName]); break; } else if (unsortedChar == '0' && sortedChar != '0') { //The unsorted name ended sooner //namesUnsorted[i][checkChar] = '0'; //Move the sorted name down one and place the //unsorted name to where the sorted one was CopyString(namesSorted[(onName - 1)], namesSorted[onName]); CopyString(namesUnsorted[i], namesSorted[(onName - 1)]); break;
  • 5. } //Debug if (doDebug) { cout << "S: " << sortedChar << " | U: " << unsortedChar << endl; } if (sortedChar > unsortedChar) //Sorted is higher { //Move the sorted name down one and place the //unsorted name to where the sorted one was CopyString(namesSorted[(onName - 1)], namesSorted[onName]); CopyString(namesUnsorted[i], namesSorted[(onName - 1)]); break; } else if (sortedChar < unsortedChar) { //Keep the sorted name where it is and place the //unsorted name in the entry below CopyString(namesUnsorted[i], namesSorted[onName]); } //If it's checking the final char and no match has //been found, they must be the same if (checkChar == 23) { CopyString(namesUnsorted[i], namesSorted[onName]); } } } else {
  • 6. CopyString(namesUnsorted[i], namesSorted[onName]); } onName++; } } } cout << endl << "Sorted names: " << endl; for (int i = 0; i < nameAmount; i++) { cout << namesSorted[i] << endl; } char outputFileName[50]; cout << "Enter output file name (including extension): "; cin >> outputFileName; outputFileName[49] = '0'; ofstream outputFile; outputFile.open(outputFileName); for (int i = 0; i < nameAmount; i++) { outputFile << namesSorted[i] << " "; }
  • 7. outputFile.close(); cout << "Sorted list successfully stored in " << outputFileName << endl; return 0; } void CopyString (char string1[24], char string2[24]) { for (int i = 0; i < 24; i++) { string2[i] = string1[i]; } string2[23] = '0'; return; } input.txt Milda Dan Dale Letha Kurt Daniel Kandy Tammy Malisa Corey output.txt Corey Dale Dan
  • 8. Daniel Kandy Kurt Letha Malisa Milda Tammy Solution #include #include //Might end up not being used #include using namespace std; void CopyString (char string1[24], char string2[24]); int main () { int doDebug = 0; cout << "Do Debug Output? [Y/N]:"; char response; cin >> response; if (response == 'y' || response == 'Y') { doDebug = 1; } int nameAmount; char inputFileName[50];
  • 9. cout << "Input the name of the file to be read (Include the extension, "; cout << "must be less than 48 characters): "; cin >> inputFileName; inputFileName[49] = '0'; //To ensure null terminator cout << "Input the number of names: "; cin >> nameAmount; char namesUnsorted[nameAmount][24]; char namesSorted[nameAmount][24]; ifstream inputFile; inputFile.open(inputFileName); for (int i = 0; i < nameAmount; i++) { inputFile.getline(namesUnsorted[i], 24, ' '); namesUnsorted[i][23] = '0'; } inputFile.close(); cout << "Found the following entries in " << inputFileName << ":" << endl; for (int i = 0; i < nameAmount; i++) { cout << namesUnsorted[i] << endl;
  • 10. } //Debug if (doDebug) { cout << "The following chars were found in entry 3: " << endl; for (int i = 0; namesUnsorted[3][i] != '0'; i++) { cout << "'" << namesUnsorted[3][i] << "'" << endl; } } //Char values A-Z = [65, 90], a-z = [97, 122] //To go from lower to upper, subtract 32 //To keep track of which position is next in the sorted array int onName = 0; //Begin main sorting algorithm //Go through every letter for (char thisLetter = 'A'; thisLetter <= 'Z'; thisLetter++) { //Go through every name in the unsorted array for (int i = 0; i < nameAmount; i++) { //If a match is found if (namesUnsorted[i][0] == thisLetter) { //If there is already a name entered before and it starts with //the same letter as the match found if ((onName > 0) && (namesSorted[(onName - 1)][0] == thisLetter)) { cout << "Comparing " << namesSorted[(onName - 1)] << namesUnsorted[i] << endl;
  • 11. //Go through every letter to find which is lower for (int checkChar = 0; checkChar < 24; checkChar++) { char sortedChar, unsortedChar; sortedChar = namesSorted[onName - 1][checkChar]; unsortedChar = namesUnsorted[i][checkChar]; //If the char is a lowercase letter, convert to //uppercase if (sortedChar > 'Z') { sortedChar -= 32; } if (unsortedChar > 'Z') { unsortedChar -= 32; } //The sorted name ended sooner if (sortedChar == '0' && unsortedChar != '0') { //namesSorted[onName - 1][checkChar] = '0'; //Keep the sorted name where it is and place the //unsorted name in the entry below CopyString(namesUnsorted[i], namesSorted[onName]); break; } else if (unsortedChar == '0' && sortedChar != '0') { //The unsorted name ended sooner
  • 12. //namesUnsorted[i][checkChar] = '0'; //Move the sorted name down one and place the //unsorted name to where the sorted one was CopyString(namesSorted[(onName - 1)], namesSorted[onName]); CopyString(namesUnsorted[i], namesSorted[(onName - 1)]); break; } //Debug if (doDebug) { cout << "S: " << sortedChar << " | U: " << unsortedChar << endl; } if (sortedChar > unsortedChar) //Sorted is higher { //Move the sorted name down one and place the //unsorted name to where the sorted one was CopyString(namesSorted[(onName - 1)], namesSorted[onName]); CopyString(namesUnsorted[i], namesSorted[(onName - 1)]); break; } else if (sortedChar < unsortedChar) { //Keep the sorted name where it is and place the //unsorted name in the entry below CopyString(namesUnsorted[i], namesSorted[onName]); } //If it's checking the final char and no match has //been found, they must be the same
  • 13. if (checkChar == 23) { CopyString(namesUnsorted[i], namesSorted[onName]); } } } else { CopyString(namesUnsorted[i], namesSorted[onName]); } onName++; } } } cout << endl << "Sorted names: " << endl; for (int i = 0; i < nameAmount; i++) { cout << namesSorted[i] << endl; } char outputFileName[50]; cout << "Enter output file name (including extension): "; cin >> outputFileName; outputFileName[49] = '0';
  • 14. ofstream outputFile; outputFile.open(outputFileName); for (int i = 0; i < nameAmount; i++) { outputFile << namesSorted[i] << " "; } outputFile.close(); cout << "Sorted list successfully stored in " << outputFileName << endl; return 0; } void CopyString (char string1[24], char string2[24]) { for (int i = 0; i < 24; i++) { string2[i] = string1[i]; } string2[23] = '0'; return; } input.txt Milda Dan Dale Letha Kurt