Adsız Assignment71 (300Points) PARTI Question1 Inthisquestion,youwillreadwordsfromafileandplacethemintoanarrayoftype string. 1-...

1 answer below »
attached


Adsız Assignment71 (300Points) PARTI Question1 Inthisquestion,youwillreadwordsfromafileandplacethemintoanarrayoftype string. 1- Makeadatatextfile“words.txt”–thatcontainsonewordoneachline.Useat least20words. 2- Nowwriteaprogramthatreadsthewordsinthefileintoanarrayofstrings (arepeatedwordshouldnotbeinsertedintothearray–yourprogram shouldnotallowthatandyoushouldmakesureyourdatafilehasduplicate wordstotestthisfunctionality).Makeyourarraysizeenoughtohold1000 words.Toreadthewordsintothearray,youshouldmakeafunctionthat takesastringarray,adatasizeinteger(dsize)byreferenceandanifstream– pleaselookattheexamplewedidinclass. 3- Declareyourarrayandfilestreamsinmainandcallthefunctionthatreads thedataintothearray. 4- WriteaprintArrayfunctionthattakesastringarray,thedsizeandan ostreamobjectsothatyoucouldprinttotheconsoleortoanoutputfile. 5- PrintyourarrayfrommainbycallingtheprintArrayfunction–oncetothe consoleandoncetoafile“wordsoutput.txt”. 6- UsetheselectionSortAlgorithmthatwecoveredinclasstosortthearray. 7- Repeat#5andmakesurethearrayissorted. 8- Findthemaximumstringandtheminimumstringinthearray(remember arraysarecomparedbasedontheASCIIvalue). 9- Writeafunctionthattakesastringandconvertseverycharacterofitto uppercase.Nowcallthatfunctionfromafunctionthatyoupassthearrayand dsizeto,touppercaseallwordsinthearray(convertallwordsinthearrayto uppercaseletter)andcallthatfrommainpassingyourarraytothatfunction. Printthearray. Question2 A. Inthisquestion,youwillreadtwodatafilesthatincludeintegersintotwo differentarrays–thesamewaywedidinclass(butwearedoingtoarrays here).Duplicatesareok. 1- Afteryoureadthedataintothearray(useonefunctionthattakesanint arrayandadsizebyreferencejustlikewedidinclass,andcallthatfrom maintofillbotharrays). 1Allnumbersinthisassignmentshouldbeformattedto2decimalpoints. 2- IncludeaprintArrayfunctionsothatyoucouldprintthetwoarrays.Use arraysize1000. 3- Useasortalgorithmtosortbotharrays. 4- NowwriteacompareOrderfunctionthattakestwoarraysandtheirdata sizes.Ifthedatasizeisthesameandeveryelementinthefirstarrayisequal toelementinthesamecorrespondingpositioninthesecondarray(both sorted)–thenthearraysareequal(return0).Iftheveryfirstelementthatis differentislargerinonearraythantheotherarraythenthefirstarrayis larger(return1)otherwise(return-1).Ifthedsizesaredifferent,thelonger arrayislarger(return1ifarray1islargerthanarray2and-1otherwise). 5- CallthecompareOrderfunctionfrommainpassingyourtwoarraysandtheir correspondingdsizesandgiveappropriatemessages.(PleaseseeHint- required). 6- NowwriteacompareSumtocomparethetwoarraysbasedonthesumof theirelements–followthesamethemeofreturning0,1or-1–andcallfrom mainwithappropriatemessaging(pleaseseeHint-required). B. Makeanewprogram.Copyallyourcodeanditchangeitsothatitusesa vectorinsteadofanarray.Youdon’thavetouseapresetsizeforthevector. Hint:InsteadofcallingcompareOrderandCompareSumandincludinglogiccodefor messaginginmain(ugly),writeavoidwrapperfunctioncomparethatwouldtakea comparetype,thearraysandtheirdsizesandwillcalltheappropriatecompare functionwiththearraysandthedsizesandproducetheappropriatemessaging). PartII Your task is to read a file that consists of credit card accounts, calculate interest charges,updatethebalanceandwritetheinformationtoanewfile. Tasks A. Openatextfileandtypeatleasttenrecords(eachfullrecordofanaccount should be on a separate line) 2 . Each record will consist of the following items separatedbyspaces: 1- CreditCard(16digits–nodashesorspaces–youshouldconsidertheseas charactersbecauseyouwillnotdoanyarithmeticoperationsoncreditcard numbers).Youshoulduseastringvariableforcreditcardnumber. 2- FirstName. 3- LastName. 4- InterestRate(between11.4%and24.9%) 2Pleasedon’tuseTextEditontheMactocreateyourtextdata.DownloadSublime andusethatasyourtexteditor–otherwise,youmayhaveproblems. 5- BalancefromPreviousstatement. 6- Currentcharges. Savethefileas“balances.txt”3. B. NowwriteaC++programthatwouldreadeachrecord,calculatetheinterest chargesonthepreviousbalanceforthecurrentperiod(onemonth),addthecurrent charges,calculate thenewbalanceandwriteout thesamerecord formatwiththe newly calculated balance (and 0 current charges of course). Name the file “newbalance.txt”. You should use a function that returns a double to make the calculationof thenewbalance.Your functionshould takeparametersof (interest rate,previousbalance, andcurrent charges)and returnnewbalance.Pleasedon’t forgettodividetheinterestrateby12togetthemonthlyrate. C.Runyourprogram.Pasteyourcodeintoaworddocument,takescreenshots(no phone pictures) of the output. Please upload theword document alongwith your “balance.txt”and“newbalance.txt”filestoBB. PartIII 1- Write a struct or a class PersonType which will have firstName,lastName,eID(asanint),salary,andtitle 2- WriteastructoraclassCompanyTypethatwillhaveancID, Name,City,StateandEmployeeasanarrayofPersonType– letuslimitourexercisetocompaniesofsize1000orless– andthenumberofemployeesasmembers. 3- Hide all variables for EmployeeType and CompanyType – exceptthearrayinCompamyType. 4- Writeparameterizedconstructors foreachstruct/class–a personcanbeinstantiatedbyallitsattributesexceptsalary and title. A company can be instantiated by ID, name and current number of employees (startwith 0 at the time of instantiation). 5- Writeappropriategettersandsettersforeach.Toreturna list of the employees of the company, you obviously can’t returnanarray.Butifyouuseavectoryoucould.Ignorethat particular getter – and I will do that part with you on 3Pleasemakesureyourcursorisattheendofthelastrecordnotatthebeginningof anewline. Thursday. 6- Add a void method hire to CompanyType that takes as parameter a PersonType, salary, title. Themethod should addanemployeetothearrayofemployeesofthatcompany, andsetthesalaryandtitleofthatPerson. 7- Add a method to Employee called giveRaise with a percentage. 8- Inmain()– a. Makeadatafilethatincludesemployees,andanother one that includes companies, load them in, and Instantiate a the Companies and Persons –making surethatanemployeeworksforanexistingcompany in the company file – if an employee works for a companythatdoesnotexistinthecompanyfile,you needtoaddthecompany–yourlogicshouldbeable todothis. b. DeclareaanarrayoravectorofCompanyTypeand addallcompaniestothearrayorvector. c. Loop through companies and print each company followedbytheemployeesworkinginthecompany. d. Printtheavgsalarypercompany. e. Printthetotalavgsalaryacrosscompanies. f. Assume each companywill give a raise that ranges between3%-5%.Assignsucharaisetoeachcompany randomly and then give its employees a raise, and redopartsdande. g. Sortallemployeesofallcompaniesbysalary h. Sortallcompaniesbytheavgoftheirsalaries. i. Write a method or methods to have an employee movefromonecompanytoanother. Submission 1- Submityourcppfilespastedinaworddocument.Pastethecodenotan image. 2- Submitthedatafilesyouusedseparatelyasfilesnotpastedintheword document. 3- Includeascreenshotofeveryoutputforeachcase.Noscreenshots= ZERO.Youmustpastethescreenshotwiththeappropriatequestionin theworddocument–Iwillnotacceptimagefiles.Youneedtofollow instructionsofhowtosubmit. 4- ForQuestion2ofPartI,pleasemakedifferentsetsoftwodatafilesto testyourcodeforallcases.
Answered Same DayMay 05, 2021

Answer To: Adsız Assignment71 (300Points) PARTI Question1...

Kashish answered on May 06 2021
152 Votes
Part-1 Question-1
/*Question 1
In this question, you will read words from a file and place them into an array of type string.
1- Make a data text file “words.txt†– that contains one word on each line. Use at least 20 words.
2- Now write a program that reads the words in the file into an array of strings (a repeated word should not be inserted into the array – your program should not allow that and you should make sure your data file has duplicate words to test this functionality). Make your array size enough to hold 1000 words. To read the words into the array, you should make a function that takes a string array, a data size integer (dsize) by referen
ce and an ifstream – please look at the example we did in class.
3- Declare your array and file streams in main and call the function that reads the data into the array.
4- Write a printArray function that takes a string array, the dsize and an ostream object so that you could print to the console or to an output file.
5- Print your array from main by calling the printArray function – once to the console and once to a file “wordsoutput.txtâ€.
6- Use the selectionSort Algorithm that we covered in class to sort the array.
7- Repeat #5 and make sure the array is sorted.
8- Find the maximum string and the minimum string in the array (remember arrays are compared based on the ASCII value).
9- Write a function that takes a string and converts every character of it to uppercase. Now call that function from a function that you pass the array and dsize to, to uppercase all words in the array (convert all words in the array to uppercase letter) and call that from main passing your array to that function. Print the array.

*/
//*******************************************************************
#include
#include
#include
using namespace std;
int const ARRAY_SZ = 50;
void toUpperString(string &s){
for(int i=0;i s[i]=toupper(s[i]);
}
}
string getMin(string const a[], int const dsize){
string min = a[0];
for(int i=1;i if (a[i] min = a[i];
}
}
return min;
}
string getMax(string const a[], int const dsize){
string max = a[0];
for(int i=0;i if (a[i]>max){
max = a[i];
}
}
return max;
}
bool openifile(string filename, ifstream &fin){
fin.open(filename.c_str());
if(!fin){ cout<< "Error opening input file.."<< endl; return false;}
return true;
}
bool openofile(string filename, ofstream &fout){
fout.open(filename.c_str());
if(!fout){ cout<< "Error opening output file.."<< endl; return false;}
return true;
}
bool found(string words[],string word,int dsize){
for(int i=0;i if(words[i]==word)
return true;
}
return false;
}
void readWords(string words[],int &dsize,ifstream &fin){
int i=0;
while(!fin.eof()){
string word;
fin >> word;
if (found(words,word,i)){
cout << word << " already exists in the array - skipping" << endl;
continue;
}
words[i] = word;
i++;
}
dsize = i;
}
void printWordsArray(string words[],int const dsize, ostream &out){
for(int i=0;i out << words[i] << endl;
}
}
void swap(string &a, string &b){
string temp;
temp = a;
a=b;
b=temp;
}
void selectionSort(string a[],int dsize){

int i;
for(i=0;i int locmin = i;
for(int j=i+1;j if(a[j] locmin=j;
}

if(locmin!=i){
swap(a[locmin],a[i]);
}
}
}
void toUpperStringArray(string words[],int dsize){
for(int i=0;i toUpperString(words[i]);
}
}
int main(){

string words[ARRAY_SZ];
int dsize=0;
string ifilename = "words.txt";
string ofilename = "wordsoutput2.txt";
ifstream fin;
ofstream fout;
if(!openifile(ifilename,fin)){ exit(1);}
readWords(words,dsize,fin);
cout << dsize << " words have been read into the array.." << endl;
if(!openofile(ofilename,fout)){exit(1);}
printWordsArray(words,dsize,cout);
printWordsArray(words,dsize,fout);
selectionSort(words,dsize);
cout<< "===================" << endl;
printWordsArray(words,dsize,cout);
cout << "MinWord=" << getMin(words,dsize) << '\t' << "MaxWord=" << getMax(words,dsize) << endl;
toUpperStringArray(words,dsize);
cout << "===============" << endl;
printWordsArray(words,dsize,cout);

return 0;
}
Part-1 Question-2
/*
Question 2

In this question, you will read two data files that include integers into two different arrays – the same way we did in class (but we are doing to arrays here). Duplicates are ok.

1- After you read the data into the array (use one function that takes an int array and a dsize by reference just like we did in class, and call that from main to fill both arrays).
2- Include a printArray function so that you could print the two arrays. Use array size 1000.
3- Use a sort algorithm to sort both arrays.
4- Now write a compareOrder function that takes two arrays and their data sizes. If the data size is the same and every element in the first array is equal to element in the same corresponding position in the second array (both sorted) – then the arrays are equal (return 0). If the very first element that is different is larger in one array than the other array then the first array is larger (return 1) otherwise (return -1). If the dsizes are different, the longer array is larger (return 1 if array1 is larger than array 2 and -1 otherwise).
5- Call the compareOrder function from main passing your two arrays and their corresponding dsizes and give appropriate messages. (Please see Hint - required).
6- Now write a compareSum to compare the two arrays based on the sum of their elements – follow the same theme of returning 0,1 or -1 – and call from main with appropriate messaging (please see Hint - required).

Hint: Instead of calling compareOrder and CompareSum and including logic code for messaging in main (ugly), write a void wrapper function compare that would take a compare type, the arrays and their dsizes and will call the appropriate compare function with the arrays and the dsizes and produce the appropriate messaging).


*/
#include
#include
#include
using namespace std;
int const ARRAY_SZ = 1000;
bool openofile(string filename, ofstream &fout){
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here