Write code in main that will read in 6 ints and store them into
the list values. When you read a positive number
it should be added to the back of the list. When you read a
negative number, it should be inserted at the front of the
list.
Example: Given input 5 2 -4 3 -1 6, you would build up:
5 5 2 -4 5 2 -4 5 2 3 -1 -4 5 2 3 -1 -4 5 2 3 6
#include <iostream>
#include <list>
using namespace std;
template <class T>
void print(const list<T>& v) {
for (auto myIt = v.begin(); myIt != v.end(); ++myIt) {
cout << *myIt << " ";
}
cout << endl;
}
int main() {
list<int> values;
//Do not modify anything on or above the line below this
//YOUR_CODE_BELOW
//YOUR_CODE
//YOUR_CODE_ABOVE
//Do not modify anything on or below the line above this
print(values);
}
#include <iostream>
#include <list>
using namespace std;
template<class T>
void print(const list<T> &v) {
for (auto myIt = v.begin(); myIt != v.end(); ++myIt) {
cout << *myIt << " ";
}
cout << endl;
}
int main() {
list<int> values;
//Do not modify anything on or above the line below this
//YOUR_CODE_BELOW
int num;
for (int i = 0; i < 6; ++i) {
cin >> num;
if (num < 0) {
values.push_front(num);
} else {
values.push_back(num);
}
}
//YOUR_CODE_ABOVE
//Do not modify anything on or below the line above this
print(values);
}
Write code in main that will read in 6 ints and store them into the list...
Vectors. This lab is to be done using Unix. To familiarize yourself with Unix, read this tutorial. To prove that you used Unix tools, as part of your project submission, you need to submit a typescript file with the record of at least one successful compilation of the second project programs below (the execution of the compiler on your source code file). Create a project titled Lab12_Vectors. Implement the dynamically expanding and contracting container functionality described in previous labs using...
Make an abstract class Number that allows the rest of the code to work correctly. printDoubled should be able to take either an Int or a Double and print out twice its value. #include <iostream> using namespace std; //Do not modify anything on or above the line below this //YOUR_CODE_BELOW //YOUR_CODE //YOUR_CODE_ABOVE //Do not modify anything on or below the line above this void printDoubled(const Number& n) { cout << n.getValue() * 2 << endl; } class Int : public...
I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() { int var1 = 20 ; int var2 = 30 ; int* ptr1 ; int* ptr2 ; int* temp ; ptr1 = &var1 ; ptr2 = &var2 ; cout << *ptr1 << endl ;...
Write a templated function sumList that will take in an array of any type and the length of the array. It should add all the elements in the array and return the total. Hint: you can declare a variable sum of type T and initialize it like this: T sum {}; The {} are the best way to make sure that numbers get set to 0, a string gets created as empty etc... #include <iostream> using namespace std; //Do not...
/* Graph read from file, and represnted as adjacency list.
To implement DFS and BFS on the graph
*/
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <utility>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
// Each vertex has an integer id.
typedef vector<vector<pair<int,int>>> adjlist; //
Pair: (head vertex, edge weight)
adjlist makeGraph(ifstream& ifs);
void printGraph(const adjlist& alist);
vector<int> BFS(const adjlist& alist, int source); //
Return vertices in BFS order
vector<int> DFS(const adjlist& alist, int source); //...
//This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...
//This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...
Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public: static string weekDays[7]; void print() const; string nextDay() const; string prevDay() const; void addDay(int nDays); void setDay(string d); string getDay() const; dayType(); dayType(string d); private: string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...
soccerApp.cpp is used to test your code and contains the main function. No changes to this file are necessary. Inside of the soccerPlayer.cpp file, implement the three member functions that are specified in soccerPlayer.hpp. The member function definition for print is already provided. soccerPlayer.cpp: #include "soccerPlayer.hpp" void TopTwoPlayer::print() const { cout << left << setw(8) << "Name: " << setw(18) << name << setw(10) << "Country:" << setw(18) << country << setw(14) << "appearances:" << right << setw(3) << appearances...