Hi, need this question ansered in c++, has multiple levels will post again if you can complete every level so keep an eye out for that.
here is a sketch of the program from the screenshot
int main (int argc, char** argv) { enum { total, unique } mode = total; for (int c; (c = getopt(argc, argv, "tu")) != -1;) { switch(c) { case 't': mode = total; break; case 'u': mode = unique; break; } } argc -= optind; argv += optind; string word; int count = 0; while (cin >> word) { count += 1; } switch (mode) { case total: cout << "Total: " << count << endl; break; case unique: cout << "Unique: " << "** missing **" << endl; break; } }
you'll have to copy and paste formatted
main.cpp
#include <string>
#include <vector>
#include <iostream>
#include <typeinfo>
#include <unistd.h>
using namespace std;
int main(int argc, char** argv)
{
enum {total, unique} mode = total;
for (int c; (c = getopt(argc, argv, "tu")) !=
-1;)
{
switch(c)
{
case 't': mode = total; break;
case 'u': mode = unique; break;
}
}
argc -= optind;
argv += optind;
string word;
vector <string> words;
int count = 0;
while (cin >> word)
{
count += 1;
bool repeated =
false;
for (auto it =
words.begin(); it < words.end(); ++it)
{
if ((*it) == word)
{
repeated = true;
break;
}
}
if (!repeated)
{
words.push_back(word);
}
}
switch (mode)
{
case total: cout
<< "Total: " << count << endl; break;
case unique: cout
<< "Unique: " << words.size() << endl;
break;
}
return 0;
}
main.cpp
#include <string>
#include <iostream>
#include <unistd.h>
using namespace std;
template <class T>
class Vector
{
public:
typedef T*
iterator;
Vector()
{
used = 0;
}
iterator begin()
{
return items;
}
iterator end()
{
return items + used;
}
int size()
{
return used;
}
iterator insert(iterator
position, const T& item)
{
for (iterator it = end(); it > position; --it)
{
*it = *(it - 1);
}
*position = item;
used ++;
return position;
}
private:
T items[1000];
int used;
};
int main(int argc, char** argv)
{
enum {total, unique} mode = total;
for (int c; (c = getopt(argc, argv, "tu")) !=
-1;)
{
switch(c)
{
case 't': mode = total; break;
case 'u': mode = unique; break;
}
}
argc -= optind;
argv += optind;
string word;
Vector <string> words;
int count = 0;
while (cin >> word)
{
count += 1;
bool repeated =
false;
for (auto
it=words.begin(); it<words.end(); ++it)
{
if ((*it) == word)
{
repeated = true;
}
}
if (!repeated)
{
words.insert(words.end(), word);
}
}
switch (mode)
{
case total: cout
<< "Total: " << count << endl; break;
case unique: cout
<< "Unique: " << words.size() << endl;
break;
}
return 0;
}
main.cpp
#include <string>
#include <algorithm>
#include <iostream>
#include <unistd.h>
using namespace std;
class WordInfo
{
public:
string text;
int count;
WordInfo()
{
text = "";
count = 0;
}
WordInfo(string
mText, int mCount)
{
text = mText;
count= mCount;
}
};
bool myCompare(WordInfo i1, WordInfo i2)
{
return i1.text < i2.text;
}
template <class T>
class Vector
{
public:
typedef T*
iterator;
Vector()
{
used = 0;
}
iterator begin()
{
return items;
}
iterator end()
{
return items + used;
}
int size()
{
return used;
}
iterator insert(iterator
position, const T& item)
{
for (iterator it = end(); it > position; --it)
{
*it = *(it - 1);
}
*position = item;
used ++;
return position;
}
private:
T items[1000];
int used;
};
int main(int argc, char** argv)
{
enum {total, unique, indiv} mode = total;
for (int c; (c = getopt(argc, argv, "tui")) !=
-1;)
{
switch(c)
{
case 't': mode = total; break;
case 'u': mode = unique; break;
case 'i': mode = indiv; break;
}
}
argc -= optind;
argv += optind;
string word;
Vector <WordInfo> words;
int count = 0;
while (cin >> word)
{
count += 1;
bool repeated =
false;
for (auto
it=words.begin(); it<words.end(); ++it)
{
if ((*it).text == word)
{
repeated = true;
(*it).count ++;
}
}
if (!repeated)
{
WordInfo entry(word, 1);
words.insert(words.end(), entry);
}
}
switch (mode)
{
case total: cout
<< "Total: " << count << endl; break;
case unique: cout
<< "Unique: " << words.size() << endl;
break;
case indiv:
{
sort(words.begin(), words.end(), myCompare);
for (auto it = words.begin(); it < words.end(); ++it)
{
cout << (*it).text << ": " << (*it).count
<< endl;
}
break;
}
}
return 0;
}
main.cpp
#include <string>
#include <iostream>
#include <algorithm>
#include <unistd.h>
using namespace std;
class WordInfo
{
public:
string text;
int count;
WordInfo()
{
text = "";
count = 0;
}
WordInfo(string
mText, int mCount)
{
text = mText;
count= mCount;
}
};
bool myCompare(WordInfo i1, WordInfo i2)
{
return i1.text < i2.text;
}
template <class T>
class Vector
{
public:
typedef T*
iterator;
Vector()
{
used = 0;
items = new T[1000];
max_size = 1000;
}
iterator begin()
{
return items;
}
iterator end()
{
return items + used;
}
int size()
{
return used;
}
iterator insert(iterator
position, const T& item)
{
int offset = position - end();
if(used + 1 == max_size) // double the size
{
T * newItems = new T[2 * max_size];
for (int i=0; i<used; ++i)
{
newItems[i] = items[i];
}
delete []items;
items = NULL;
items = newItems;
max_size *= 2;
}
position = end() + offset;
for (iterator it = end(); it > position; --it)
{
*it = *(it - 1);
}
*position = item;
used ++;
return position;
}
private:
T * items;
int max_size;
int used;
};
int main(int argc, char** argv)
{
enum {total, unique, indiv} mode = total;
for (int c; (c = getopt(argc, argv, "tui")) !=
-1;)
{
switch(c)
{
case 't': mode = total; break;
case 'u': mode = unique; break;
case 'i': mode = indiv; break;
}
}
argc -= optind;
argv += optind;
string word;
Vector <WordInfo> words;
int count = 0;
while (cin >> word)
{
count += 1;
bool repeated =
false;
for (auto
it=words.begin(); it<words.end(); ++it)
{
if ((*it).text == word)
{
repeated = true;
(*it).count ++;
}
}
if (!repeated)
{
WordInfo entry(word, 1);
words.insert(words.end(), entry);
}
}
switch (mode)
{
case total: cout
<< "Total: " << count << endl; break;
case unique: cout
<< "Unique: " << words.size() << endl;
break;
case indiv:
{
sort(words.begin(), words.end(), myCompare);
for (auto it = words.begin(); it < words.end(); ++it)
{
cout << (*it).text << ": " << (*it).count
<< endl;
}
break;
}
}
return 0;
}
Hi, need this question ansered in c++, has multiple levels will post again if you can...
Can I get some help with this question for c++ if you can add some comments too to help understand that will be much appreciated. Code: #include <cstdlib> #include <getopt.h> #include <iostream> #include <string> using namespace std; static long comparisons = 0; static long swaps = 0; void swap(int *a, int *b) { // add code here } void selectionSort(int *first, int *last) { // add code here } void insertionSort(int *first, int *last) { // add code here }...
-can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...
C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...
The provided code is my solution, stripped of the details needed to make it work. It is not a “good” program. It lives in a single file, does not use classes, and it has those evil global variables. That is by design. I want to to craft code. Use my code as a guide to help you put together the needed parts. #include #include #include // defaults const int MAX_STEPS = 100; // how long do we run the simulation...
C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...
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...
Practical 5: Write a program that implements several sorting algorithms, and use it to demonstrate the comparative performance of the algorithms for a variety of data sets. Need Help With this Sorting Algorithm task for C++ Base Code for sorting.cpp is given. The header file is not included in this. Help would be much appreciated as I have not started on this due to personal reasons #include <cstdlib> #include <iostream> #include <getopt.h> using namespace std; long compares; // for counting...
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];...
C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...
C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...