101 Challenges In C++ Programming
eBook - ePub

101 Challenges In C++ Programming

Solve 101 Challenges to sharpen C++ Programming skills

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

101 Challenges In C++ Programming

Solve 101 Challenges to sharpen C++ Programming skills

About this book

Practice them to be a mature a C++ programmerVery often it is found that while creating C++ programs programmers are simply doing C programming with a C++ compiler. As a result, they are unable to exploit the real power that C++ lays at their door steps. Also there are not enough challenges/problems available in text books that would test the programmer' understanding of C++ and OOP concepts. To address these issues Authors have crafted well thought out this book. Their complete solution, sample runs and explanation. These challenges would test and improve your knowledge in every aspect of C++ programming.KEY FEATURES• Strengthens the foundations, as detailed explanation of programming language concepts are given.. • Lists down all important points that you need to know related to various topics in an organized manner.• Prepares you for coding related interview and theoretical questions.• Provides In depth explanation of complex topics and Questions.• Focuses on how to think logically to solve a problem.• Follows systematic approach that will help you to prepare for an interview in short duration of time. WHAT WILL YOU LEARN• Basic C++, Class organization, Class constructor, Classes and Objects, Function challenges• Function, Operator overloading challenges• Free store, Inheritance, Virtual function, Input/output, Exception handling, STL challenges WHO THIS BOOK IS FORStudents, Programmers, researchers, and software developers who wish to learn the basics of C programming language.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
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 use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access 101 Challenges In C++ Programming by Yashavant Kanetkar,Aditya Kanetkar 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.

07

More Classes and Objects Challenges

Challenges: 6

This chapter tests your understanding and maturity in developing programs that involve classes and objects.

Challenge 43

Write a program to create an array class. Make a provision to perform following operations on objects of this class:
Traversal: Processing each element in the array
Search: Finding the location of an element with a given value
Insertion: Adding a new element to an array
Deletion: Removing an element from an array
Sorting: Organizing the elements in some order
Merging: Combining two arrays into a single array
Reversing: Reversing the elements of an array

Solution

// Project: chall43
// Array operations
#include <iostream>
using namespace std;
const int MAX = 5;
class array
{
private:
int arr[ MAX ];
public:
void insert (int pos, int num);
void del (int pos);
void reverse(); void display();
void search (int num);
};
// inserts an element num at given position pos
void array:: insert (int pos, int num)
{
int i;
// shift elements to right
for (i = MAX - 1; i >= pos; i--)
arr[ i ] = arr[ i - 1 ]; arr[ i ] = num;
}
// deletes an element from the given position pos
void array:: del (int pos)
{
int i;
// skip to the desired position
for (i = pos; i < MAX; i++)
arr[ i - 1 ] = arr[ i ];
arr[ i - 1 ] = 0;
}
// reverses the entire array
void array:: reverse()
{
int i;
for (i = 0; i < MAX / 2; i++)
{
int temp = arr[ i ];
arr[ i ] = arr[ MAX - 1 - i ];
arr[ MAX - 1 - i ] = temp;
}
}
// searches array for a given element num
void array:: search (int num)
{
int i;
// Traverse the array
for (i = 0; i < MAX; i++)
{
if (arr[ i ] == num)
{
cout << “\n\nThe element” << num
<< “ is present at” << (i + 1) << “th position\n”;
return;
}
}
if (i == MAX)
cout << “\n\nThe element” << num
<< “ is not present in the array\n”;
}
// displays the contents of an array
void array:: display()
{
cout << endl;
// traverse the entire array
for (int i = 0; i < MAX; i++)
cout << “” << arr[ i ];
}
int main()
{
array a;
a.insert (1,11);
a.insert (2,12);
a.insert (3,13);
a.insert (4,14);
a.insert (5,15);
cout << “\nElements of Array: “;
a.display();
a.del (5);
a.del (2);
cout << “\n\nAfter deletion: “;
a.display();
a.insert (2, 222);
a.insert (5, 555);
cout << “\n\nAfter insertion: “;
a.display();
a.reverse();
cout << “\n\nAfter reversing: “;
a.display();
a.search (222);
a.search (666);
return 0;
}

Sample Run

Elements of Array:
11 12 13 14 15
After deletion:
11 13 14 0 0
After insertion:
11 222 13 14 555
After reversing:
555 14 13 222 11
The element 222 is present at 4th position
The element 666 is not present in the array

Explanation

In this program we have designed a class called array. It contains an array arr of 5 ints. The functions like insert(), del(), display(), reverse() and search() access and manipulate the array arr.
The insert() function takes two arguments, the position pos at which the new number has to be inserted and the number num that has to be inserted. In this function,...

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. About the Authors
  6. Preface
  7. Table of Contents
  8. Chapter 01 Getting off the Ground Challenges
  9. Chapter 02 The Starters Challenges
  10. Chapter 03 Basic C++ Challenges
  11. Chapter 04 Class Organization Challenges
  12. Chapter 05 Class Constructor Challenges
  13. Chapter 06 Classes and Objects Challenges
  14. Chapter 07 More Classes and Objects Challenges
  15. Chapter 08 Function Challenges
  16. Chapter 09 Function Overloading Challenges
  17. Chapter 10 Operator Overloading Challenges
  18. Chapter 11 Free Store Challenges
  19. Chapter 12 Inheritance Challenges
  20. Chapter 13 Virtual Function Challenges
  21. Chapter 14 Input / Output Challenges
  22. Chapter 15 Template Challenges
  23. Chapter 16 Exception Handling Challenges
  24. Chapter 17 STL Challenges
  25. Chapter 18 Miscellaneous Challenges