The Modern C++ Challenge
eBook - ePub

The Modern C++ Challenge

Become an expert programmer by solving real-world problems

  1. 328 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

The Modern C++ Challenge

Become an expert programmer by solving real-world problems

Book details
Book preview
Table of contents
Citations

About This Book

Test your C++ programming skills by solving real-world programming problems covered in the book

Key Features

  • Solve a variety of real-world programming and logic problems by leveraging the power of C++17
  • Test your skills in using language features, algorithms, data structures, design patterns, and more
  • Explore areas such as cryptography, communication, and image handling in C++

Book Description

C++ is one of the most widely-used programming languages and has applications in a variety of fields, such as gaming, GUI programming, and operating systems, to name a few. Through the years, C++ has evolved into (and remains) one of the top choices for software developers worldwide. This book will show you some notable C++ features and how to implement them to meet your application needs. Each problem is unique and doesn't just test your knowledge of the language; it tests your ability to think out of the box and come up with the best solutions. With varying levels of difficulty, you'll be faced with a wide variety of challenges. And in case you're stumped, you don't have to worry: we've got the best solutions to the problems in the book. So are you up for the challenge?

What you will learn

  • Serialize and deserialize JSON and XML data
  • Perform encryption and signing to facilitate secure communication between parties
  • Embed and use SQLite databases in your applications
  • Use threads and asynchronous functions to implement generic purpose parallel algorithms
  • Compress and decompress files to/from a ZIP archive
  • Implement data structures such as circular buffer and priority queue
  • Implement general purpose algorithms as well as algorithms that solve specific problems
  • Create client-server applications that communicate over TCP/IP
  • Consume HTTP REST services
  • Use design patterns to solve real-world problems

Who this book is for

This book will appeal to C++ developers of all levels. There's a challenge inside for everyone.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access The Modern C++ Challenge by Marius Bancila in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in C++. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781788994026
Edition
1

Algorithms and Data Structures

Problems

45. Priority queue

Write a data structure that represents a priority queue that provides constant time lookup for the largest element, but has logarithmic time complexity for adding and removing elements. A queue inserts new elements at the end and removes elements from the top. By default, the queue should use operator< to compare elements, but it should be possible for the user to provide a comparison function object that returns true if the first argument is less than the second. The implementation must provide at least the following operations:
  • push() to add a new element
  • pop() to remove the top element
  • top() to provide access to the top element
  • size() to indicate the number of elements in the queue
  • empty() to indicate whether the queue is empty

46. Circular buffer

Create a data structure that represents a circular buffer of a fixed size. A circular buffer overwrites existing elements when the buffer is being filled beyond its fixed size. The class you must write should:
  • Prohibit default construction
  • Support the creation of objects with a specified size
  • Allow checking of the buffer capacity and status (empty(), full(), size(), capacity())
  • Add a new element, an operation that could potentially overwrite the oldest element in the buffer
  • Remove the oldest element from the buffer
  • Support iteration through its elements

47. Double buffer

Write a class that represents a buffer that could be written and read at the same time without the two operations colliding. A read operation must provide access to the old data while a write operation is in progress. Newly written data must be available for reading upon completion of the write operation.

48. The most frequent element in a range

Write a function that, given a range, returns the most frequent element and the number of times it appears in the range. If more than one element appears the same maximum number of times then the function should return all the elements. For instance, for the range {1,1,3,5,8,13,3,5,8,8,5}, it should return {5, 3} and {8, 3}.

49. Text histogram

Write a program that, given a text, determines and prints a histogram with the frequency of each letter of the alphabet. The frequency is the percentage of the number of appearances of each letter from the total count of letters. The program should count only the appearances of letters and ignore digits, signs, and other possible characters. The frequency must be determined based on the count of letters and not the text size.

50. Filtering a list of phone numbers

Write a function that, given a list of phone numbers, returns only the numbers that are from a specified country. The country is indicated by its phone country code, such as 44 for Great Britain. Phone numbers may start with the country code, a + followed by the country code, or have no country code. The ones from this last category must be ignored.

51. Transforming a list of phone numbers

Write a function that, given a list of phone numbers, transforms them so they all start with a specified phone country code, preceded by the + sign. Any whitespaces from a phone number should also be removed. The following is a list of input and output examples:
07555 123456 => +447555123456
07555123456 => +447555123456
+44 7555 123456 => +447555123456
44 7555 123456 => +447555123456
7555 123456 => +447555123456

52. Generating all the permutations of a string

Write a function that, prints on the console all the possible permutations of a given string. You should provide two versions of this function: one that uses recursion, and one that does not.

53. Average rating of movies

Write a program that calculates and prints the average rating of a list of movies. Each movie has a list of ratings from 1 to 10 (where 1 is the lowest and 10 is the highest rating). In order to compute the rating, you must remove 5% of the highest and lowest ratings before computing their average. The result must be displayed with a single decimal point.

54. Pairwise algorithm

Write a general-purpose function that, given a range, returns a new range with pairs of consecutive elements from the input range. Should the input range have an odd number of elements, the last one must be ignored. For example, if the input range was {1, 1, 3, 5, 8, 13, 21}, the result must be { {1, 1}, {3, 5}, {8, 13}}.

55. Zip algorithm

Write a function that, given two ranges, returns a new range with pairs of elements from the two ranges. Should the two ranges have different sizes, the result must contain as many elements as the smallest of the input ranges. For example, if the input ranges were { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } and { 1, 1, 3, 5, 8, 13, 21 }, the result should be {{1,1}, {2,1}, {3,3}, {4,5}, {5,8}, {6,13}, {7,21}}.

56. Select algorithm

Write a function that, given a range of values and a projection function, transforms each value into a new one and returns a new range with the selected values. For instance, if you have a type book that has an id, title, and author, and have a range of such book values, it should be possible for the function to select only the title of the books. Here is an example of how the function should be used:
struct book
{
int id;
std::string title;
std::string author;
};

std::vector<book> books{
{101, "The C++ Programming Language", "Bjarne Stroustrup"},
{203, "Effective Modern C++", "Scott Meyers"},
{404, "The Modern C++ Programming Cookbook", "Marius Bancila"}};

auto titles = select(books, [](book const & b) {return b.title; });

57. Sort algorithm

Write a function that, given a pair of random-access iterators to define its lower and upper bounds, sorts the elements of the range using the quicksort algorithm. There should be two overloads of the sort function: one that uses operator< to compare the elements of the r...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Math Problems
  7. Language Features
  8. Strings and Regular Expressions
  9. Streams and Filesystems
  10. Date and Time
  11. Algorithms and Data Structures
  12. Concurrency
  13. Design Patterns
  14. Data Serialization
  15. Archives, Images, and Databases
  16. Cryptography
  17. Networking and Services
  18. Bibliography
  19. Other Books You May Enjoy