SlideShare a Scribd company logo
1 of 15
Download to read offline
#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
 
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
 
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
 

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

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
 
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
 
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

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 

#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