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...
can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block { std::string word; int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) { string filename="input.txt"; //declare array of struct word_block word_block arr[SIZE]; int count = 0; if (argc < 2) { cout << "Usage: " << argv[0] << "...
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...
I'm trying to write a program that can ask a user about what type of solid they have and to be able to enter values like radius and length of the shape so the program can calculate the volume of a shape and print the result. I also want to give them a repeating option to input another shape if they want to. I'm trying to use at least 7 functions that can display an output, the volumes of a...
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;...
Please do a flowchart which will be on the computer not on paper so i can read it and be able to take screenshot for this c++ code this code for MasterMind //System Libraries #include <iostream> //Input/Output Library #include <cstdlib> #include <ctime> using namespace std; //User Libraries //Global Constants, no Global Variables are allowed //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc... //Function Prototypes //main int main(int argc, char** argv) { //Set the random number seed srand(time(0)); int randomint = (rand()%5)+1;...
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...