*****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...
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...
Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis With each guess... If the guess does not have an equal number of characters, tell the user...
/* Implementation of the main() method of the program. */ #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; class Student { public: // default constructor Student() { studentID = 0; studentFirst = "First"; studentMiddle = "Middle"; studentLast = "Last"; } void SetStudentID(int number) { studentID = number; } void SetStudentFirst(string name) { studentFirst = name; } void SetStudentMiddle(string name) { studentMiddle =...
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...
1 #include <string> 2 #include <iostream> 3 using std::string; 4 using std::cout; 5 using std::endl; 7 class Pet 8 { 9 public: 10 string name; 11 virtual void print( ) const; 12}; 13 14 class Dog:public Pet 15 { 16 public: 17 string breed; 18 virtual void print( ) const; 19}; 20 21 int main( ) 22 { 23 Dog vdog; 24 Pet vpet; 25 vdog.name = "Tiny"; 26 vdog.breed = "Great Dane"; 27 vpet =...
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];...
in
c++ please
program for this code
#include <iostream>
#include <fstream>
#include <string>
#include <cstring> // for string tokenizer and c-style
string processing
#include <algorithm> // max function
#include <stdlib.h>
#include <time.h>
using namespace std;
// Extend the code here as needed
class BTNode{
private:
int nodeid;
int data;
int levelNum;
BTNode* leftChildPtr;
BTNode* rightChildPtr;
public:
BTNode(){}
void setNodeId(int id){
nodeid = id;
}
int getNodeId(){
return nodeid;
}
void setData(int d){
data = d;
}
int getData(){
return data;...