*****Complete void example 4, 7, 8, 9, 10
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void rtrim(std::string& str, const std::string& chars =
"\t\n\v\f\r ")
{
str.erase(str.find_last_not_of(chars) + 1);
}
vector<string> *get_words() {
vector<string> *words = new vector<string>();
fstream infile;
string word;
infile.open("words.txt");
getline(infile, word);
while(infile) {
rtrim(word);
words->push_back(word);
getline(infile, word);
}
return words;
}
void example_1(vector<string> *words) {
// find words that contain the substring 'pet' and 'cat'
// HINT: use find(str, p) method. Then find more words
// using your own two words but this time use the p
// parameter to enforce the order in which the words appear.
cout << endl << "Words that contains 'pet' and 'cat' in
the same word"<< endl;
for (string word : *words) {
if (word.find("pet", 0) != string::npos)
if (word.find("cat", 0) !=
string::npos)
cout << word << endl;
}
}
void example_2(vector<string> *words) {
// find words that have exactly 5 characters with the second
letter
// is 'p' and the last letter is 'e'
cout << endl << "Words with second letter 'p', and last
letter 'e'"<< endl;
for (string word : *words) {
if(word.length()==5){
if (word[1]=='p'&&word[4]=='e')
cout<<word<<endl;
}
}
}
void example_3(vector<string> *words) {
// find words that have more then 6 characters and end with
// 'sant'
// HINT: use the length of the word to find the location of
'sant'
// int lenght;
cout << endl << "Words ending in 'sant'" <<
endl;
for (string word : *words){
if (word.length() > 6) {
if (word.find("sant", 0) != string::npos)
cout << word << endl;
}
}
}
void example_4(vector<string> *words) {
// find words longer then 3 chars that start and end with the
same
// three characters.
// HINT: use substr() and find()
cout << endl << "Starts and ends with same 3 chars."
<< endl;
}
void example_5(vector<string> *words) {
// find words that have double p's and double l's
cout << endl << "Words with 'pp' and 'll'" <<
endl;
for (string word : *words) {
if (word.find("pp", 0) != string::npos) {
cout << word << endl;
}
if (word.find("ll", 0) != string::npos)
{
cout << word << endl;
}
}
}
void example_6(vector<string> *words) {
// find words that have more then 8 letters where the
// first, fourth, seventh, and tenth letters are the same.
int length;
cout << endl << "Words with matching first, fourth,
seventh, and tenth letters" << endl;
for (string word : *words) {
if (word.length() >= 10) {
if ((word[0] ==
word[3]) && (word[3] == word[6]) &&
(word[6] == word[9])) {
cout << word << endl;
}
}
}
}
void example_7(vector<string> *words) {
// find words of any length that contains an 'x' and 'e' and a
'v'
cout << endl << "Words containing x,e and v" <<
endl;
for (string word : *words) {
}
}
void example_8(vector<string> *words) {
// find words that have an odd number of characters that
// start with 'st' and end with 'rt'
int length;
cout << endl << "Odd length words starting with 'st'
and ending with 'rt'" << endl;
}
void example_9(vector<string> *words) {
// make up your own word search..
}
void bonus(vector<string> *words) {
// 10 points. points can be applied to any missing lab.
// find palindromes - words that are spelled the same
// backwards and forwards. HINT: Use two pointers, one
// that starts at the beginning of the word and one that
// starts at the end.
char *s, *e;
int length, palindrome;
cout << endl << "Bonus palindromes" <<
endl;
}
int main() {
vector<string> *words;
words = get_words();
cout << "Words read: " << words->size() <<
endl;
example_1(words);
example_2(words);
example_3(words);
example_4(words);
example_5(words);
example_6(words);
example_7(words);
example_8(words);
example_9(words);
bonus(words);
}
100% Working C++ code:-
//*****Complete void example 4, 7, 8, 9, 10
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void rtrim(std::string& str, const std::string& chars =
"\t\n\v\f\r ")
{
str.erase(str.find_last_not_of(chars) + 1);
}
vector<string> *get_words() {
vector<string> *words = new vector<string>();
fstream infile;
string word;
infile.open("words.txt");
getline(infile, word);
while(infile) {
rtrim(word);
words->push_back(word);
getline(infile, word);
}
return words;
}
void example_1(vector<string> *words) {
// find words that contain the substring 'pet' and 'cat'
// HINT: use find(str, p) method. Then find more words
// using your own two words but this time use the p
// parameter to enforce the order in which the words appear.
cout << endl << "Words that contains 'pet' and 'cat' in
the same word"<< endl;
for (string word : *words) {
if (word.find("pet", 0) != string::npos)
if (word.find("cat", 0) != string::npos)
cout << word << endl;
}
}
void example_2(vector<string> *words) {
// find words that have exactly 5 characters with the second
letter
// is 'p' and the last letter is 'e'
cout << endl << "Words with second letter 'p', and last
letter 'e'"<< endl;
for (string word : *words) {
if(word.length()==5){
if (word[1]=='p'&&word[4]=='e')
cout<<word<<endl;
}
}
}
void example_3(vector<string> *words) {
// find words that have more then 6 characters and end with
// 'sant'
// HINT: use the length of the word to find the location of
'sant'
// int lenght;
cout << endl << "Words ending in 'sant'" <<
endl;
for (string word : *words){
if (word.length() > 6) {
if (word.find("sant", 0) != string::npos)
cout << word << endl;
}
}
}
void example_4(vector<string> *words) {
// find words longer then 3 chars that start and end with the
same
// three characters.
// HINT: use substr() and find()
cout << endl << "Starts and ends with same 3 chars." << endl;
for (string word : *words) {
int i=0;
if(word.length()>3)
{
string
first=word.substr(0,3);
string
last=word.substr(word.length()-3,word.length());
for(i=0;i<first.length();i++)
{
char
ch=first.at(i);
if(last.find(ch)==-1)
{
break;
}
}
if(i==first.length())
{
cout<<word<<endl;
}
}
}
}
void example_5(vector<string> *words) {
// find words that have double p's and double l's
cout << endl << "Words with 'pp' and 'll'" <<
endl;
for (string word : *words) {
if (word.find("pp", 0) != string::npos) {
cout << word << endl;
}
if (word.find("ll", 0) != string::npos) {
cout << word << endl;
}
}
}
void example_6(vector<string> *words) {
// find words that have more then 8 letters where the
// first, fourth, seventh, and tenth letters are the same.
int length;
cout << endl << "Words with matching first, fourth,
seventh, and tenth letters" << endl;
for (string word : *words) {
if (word.length() >= 10) {
if ((word[0] == word[3]) && (word[3] == word[6])
&&
(word[6] == word[9])) {
cout << word << endl;
}
}
}
}
void example_7(vector<string> *words) {
// find words of any length that contains an 'x' and 'e' and a
'v'
cout << endl << "Words containing x,e and v" <<
endl;
for (string word : *words) {
int x=0,e=0,v=0;
for(int
i=0;i<word.length();i++)
{
char
ch=word.at(i);
if(ch=='x')
{
x++;
}
else
if(ch=='e')
{
e++;
}
else
if(ch=='v')
{
v++;
}
}
if(x>0 && e>0
&& v>0)
{
cout<<word<<endl;
}
}
}
void example_8(vector<string> *words) {
// find words that have an odd number of characters that
// start with 'st' and end with 'rt'
int length;
cout << endl << "Odd length words starting with 'st'
and ending with 'rt'" << endl;
for (string word : *words) {
if(word.length()%2==1)
{
string st=word.substr(0,2);
string
en=word.substr(word.length()-2,word.length());
if(st=="st" &&
en=="rt")
{
cout<<word<<endl;
}
}
}
}
void example_9(vector<string> *words) {
// make up your own word search..
//My own search- starts and ends with same character
cout << endl << "words starting and ending with same character"<<endl;
for (string word : *words) {
char st=word.at(0);
char en=word.at(word.length()-1);
if(st==en)
{
cout<<word<<endl;
}
}
}
void bonus(vector<string> *words) {
// 10 points. points can be applied to any missing lab.
// find palindromes - words that are spelled the same
// backwards and forwards. HINT: Use two pointers, one
// that starts at the beginning of the word and one that
// starts at the end.
char *s, *e;
int length, palindrome;
cout << endl << "Bonus palindromes" << endl;
for (string word : *words)
{
int start=0;
int end=word.length()-1;
while(start<=end)
{
if(word.at(start)==word.at(end))
{
start++;
end--;
}
else
{
break;
}
}
if (start > end)
{
cout<<word<<endl;
}
}
}
int main() {
vector<string> *words;
words = get_words();
cout << "Words read: " << words->size() <<
endl;
example_1(words);
example_2(words);
example_3(words);
example_4(words);
example_5(words);
example_6(words);
example_7(words);
example_8(words);
example_9(words);
bonus(words);
}
*****Complete void example 4, 7, 8, 9, 10 #include <iostream> #include <fstream> #include <vector> #include <string>...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...
Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std; int is_palindrome(string word){ int len = word.size(); for(int i=0; i<len/2; i++){ if(toupper(word[i])!=toupper(word[len-i-1])) return 0; } return 1; } int have_vowels3(string word){ int cnt = 0; for(int i=0; i<word.size(); i++){ if(tolower(word[i])=='a' || tolower(word[i])=='e' || tolower(word[i])=='i' || tolower(word[i]) =='o' || tolower(word[i]) == 'u') cnt++; } if(cnt>=3) return 1; else return 0; } int have_consecutives(string word){ for(int i=0; i<word.size()-1; i++){ if(tolower(word[i])=='o' && tolower(word[i+1]=='o')) return 1; } return...
#include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return...
#include <iostream> #include <string> #include "hashT.h" #include "stateData.h" using namespace std; void stateData::setStateInfo(string sName, string sCapital, double stArea, int yAdm, int oAdm) { stateName = sName; stateCapital = sCapital; stArea = stateArea; yAdm = yearOfAdmission; oAdm = orderOfAdmission; } void stateData::getStateInfo(string& sName, string& sCapital, double& stArea, int& yAdm, int& oAdm) { sName = stateName; sCapital = stateCapital; stArea = stateArea; yAdm = yearOfAdmission; oAdm = orderOfAdmission; } string stateData::getStateName() { return stateName;...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
#include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...
employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name; std::string address; std::string phoneNum; double hrWage, hrWorked; public: Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo); std::string getName(); void setName(std::string n); int getENum(); std::string getAdd(); void setAdd(std::string a); std::string getPhone(); void setPhone(std::string p); double getWage(); void setWage(double w); double getHours(); void setHours(double h); double calcPay(double a, double b); static Employee read(std::ifstream& in); void write(std::ofstream& out); }; employee.cpp ---------- //employee.cpp #include...
moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...
In C++ write a program that will read three strings from the user, a phrase, a letter to replace, and a replacement letter. The program will change the phrase by replacing each occurrence of a letter with a replacement letter. For example, if the phrase is Mississippi and the letter to replace is 's' the new phrase will be "miizzizzippi". in the function, replace the first parameter is a modifiable string, the second parameter is the occurrence of a letter...
Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found; string document[1000][6]; ifstream infile; char s[1000];...