Question

LAB 13 Please use correct division of code into .h and .cpp files and Comments in...

LAB 13

Please use correct division of code into .h and .cpp files and Comments in code explain what's being done. Thanks you very much for your help

Create an STL vector of 10 integers and store initial values (0 to 9 is fine).
Use the std::random_shuffle algorithm to shuffle the list.
Print the list. (use an iterator in a regular for loop)
Use the std::sort algorithm to sort the list.
Print the list again. (use a range-based for loop)

Optional Challenge: use a predicate to remove the even numbers, then print the list. Which std algorithm should you use?

You will need to locate the documentation for random_shuffle, sort, and for each either in VS help or with Google. Once you leave this class, you will need to be able to find information like this on your own.

Checklist

1. Uncheck the Create directory for solution checkbox in the New Project Dialog
2. Project/solution named correctly
3. Correct comments at top
4. Consistent indentation (Use Edit/Advanced/Format Document)
5. Good variable names
6. Overall neat organization
7. Comments in code explain what's being done
8. Correct division of code into .h and .cpp files
9. Use of #pragma once in .h files (or, #ifndef)
10. #include "stdafx.h" in cpp files (or, suppress pch)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <bits/stdc++.h>
// #include <stdafx.h>
//uncomment the above header when running in visual studio
#ifndef vsize
#define vsize 10
#endif
using namespace std;

int main()
{
   vector <int> v(vsize);// Declaring vector of size 10
   for (int i=0;i<v.size();i++){
       v[i] = i;
   }
   //using random shuffle
   random_shuffle(v.begin(),v.end());

   vector <int> :: iterator it; //Declaring iterator
   cout<<"Printing using iterator\n";
   for(it = v.begin();it!=v.end();it++){
       cout<<*it<<endl;
   }

   sort(v.begin(),v.end()); // Using sort function
   cout<<"After sorting ,printing using index\n";
   for(int i=0;i<v.size();i++){
       cout<<v[i]<<endl;
   }
}

Duex Machina ApplicationsSublime Text Sun Nov 4, 14:34. File Edit Selection Find View Goto Tools Project Preferernes Help Printing using iterator GROUP 2 10 10 6 11 9 12 After sorting,printing using index 13 텨 14 1 15 2 16 3 1 15 1 18 15 20 17 4 18 5 19 6 20 7 21 8 22 9 23 26 28 29 [Finished in 1.1s]

Note: If any doubts then please comment. Hope it helps

Add a comment
Know the answer?
Add Answer to:
LAB 13 Please use correct division of code into .h and .cpp files and Comments in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Here is an example of how you separate your code into different files add the header...

    Here is an example of how you separate your code into different files add the header file and the .cpp file to the project. ------------------------------------------------------------------ //Header file -- saved as ex1.hpp #pragma once class ex1 { public: ...ex1(){} ...void print(); }; ------------------------------------------------------------------ //.cpp file -- saved as ex1.cpp #include "ex1.hpp" #include void ex1::print() { ...std::cout<<"Hello"< } ------------------------------------------------------------------ //main -- saved as main.cpp #include "ex1.hpp" int main(void) { ...ex1 e(); ...e.print(); ...return 0; } ------------------------------------------------------------------ Why do I have the #pragma...

  • Please include all .cpp/.h files if neccesary, this is in C++ Sort an array of 10,000...

    Please include all .cpp/.h files if neccesary, this is in C++ Sort an array of 10,000 elements using the quick sort algorithm as follows: a- sort the array using pivot as the middle element of the array. b- Sort the array using pivot as the median of the fist,last and middle elements of the array . c- sort the array using pivot as the middle element of the array.However ,when the size of any sub list reduces to less than...

  • Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only....

    Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only. Thank you. Pointers and Dynamic Memory – Chapter 11 1. Write code using pointers and the Accounts class from week 1 assignment as follows – create a program in which you a. Create 10 accounts using an array with id’s 0 to 9 and refer to each account using pointer notation b. Add an initial balance of...

  • Programming in C/C++ Submit your source code files (all .h and .cpp files) NO GLOBAL VARIABLES...

    Programming in C/C++ Submit your source code files (all .h and .cpp files) NO GLOBAL VARIABLES Program: Use operator overloaded functions for a birthday club – Based on Chapter 11 lecture (25 pts) Make a class called Birthday that will have a date of month, day, and year and the name. Need to have overloaded operators to compare values along with regular functions like: Overload operator == that takes a Birthdate, compares against the current date values, and returns a...

  • C++ PRPGRAM- double-linked lists Create the .h and .cpp files for an Element class that contains...

    C++ PRPGRAM- double-linked lists Create the .h and .cpp files for an Element class that contains the data and pointers for a double-link list for this application. Your linked list must consist of objects of this class. The class should contain at least the following elements (you may have more if you wish): The standard four constructors (default, parameterized, copy, move) The standard assignment operators (copy, move) A destructor Stream operators (<< and >>) The standard relational operators (<, <=,...

  • Please help me modify the Stash3.cpp and Stash3.h files below to utilize default arguments in the...

    Please help me modify the Stash3.cpp and Stash3.h files below to utilize default arguments in the constructor. Please test the constructor by creating two different versions of a Stash object. Please see the source code below: //Stash3.cpp //: C07:Stash3.cpp {O} // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Function overloading #include "Stash3.h" #include "../require.h" #include <iostream> #include <cassert> using namespace std; const int increment = 100;...

  • Need help with this C++ assignment, please use comments so I can better understand your code...

    Need help with this C++ assignment, please use comments so I can better understand your code like comments above your function header explaining what the function does and the purpose of each variable. etc. Assignment: Write a C++ program that reads a text file containing a list of movies "Movie_entries.txt" . Each line in the file contains tile, director, genre, year released and running time of a specific movie. Each field is separated by comma. Print out movie titles sorted...

  • Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and...

    Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and please add comments for the whole code. Include a class diagrams, and explain the approach you used for the project and how you implemented that, briefly in a few sentences. Please note the following: -Names chosen for classes, functions, and variables should effectively convey the purpose and meaning of the named entity. - Code duplication should be avoided by factoring out common code into...

  • This is a C++ programming question. Please provide the correct, workable code. Use the following three...

    This is a C++ programming question. Please provide the correct, workable code. Use the following three programs to help solve the problem. Provide comments throughout the code. Problem to solve: Code 1: Complex.h #pragma once #ifndef COMPLEX_H #define COMPLEX_H class Complex { private:    double real;    double imag; public:    // initialize the complex number to 0.0    Complex() : real(0.0), imag(0.0) {}    // initialize the complex number at declaration or new    Complex(double r, double i) :...

  • C++ program: can you help create a autocorrect code using the cpp code provided and the...

    C++ program: can you help create a autocorrect code using the cpp code provided and the words below using pairs, vectors and unordered map: Objectives To practice using C++ std::pair, std::vector, and std::unordered_map To tie together what we've learned into the context of a real-world application used by millions of people every day Instructions For Full Credit You're given a short list of words in known_words_short.txt that contains a handful of very different words. Assume this short list of words...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT