"" 30 Days Of Code ""
In this repository you can find the answers to the question given to you everyday !!!
So its DAY 30 and the Topic is "Priority Queue"
For a reference visit the following links -
https://www.tutorialspoint.com/cplusplus-program-to-implement-priority-queue
https://appdividend.com/2019/10/09/priority-queue-in-cpp-example-cpp-priority-queue-program/
https://www.thecrazyprogrammer.com/2017/06/priority-queue-c-c.html
And the Problem Statement is -
Write a program in C++ using priority queue in which the user will enter a value & set its priority by assigning it a number and on the basis of the priority the value has, it will be deleted (when Delete() is called). Smaller the number assigned to a value, higher its priority.
So its DAY 29 and the Topic is "Heap Sort"
For a reference visit the following links -
https://www.programiz.com/dsa/heap-sort
https://www.geeksforgeeks.org/cpp-program-for-heap-sort/
And the Problem Statement is -
Write a program in C++ to sort an integer array using the concept of Heap Sort.
So its DAY 28 and the Topic is "AVL Tree"
For a reference visit the following links -
https://www.tutorialspoint.com/cplusplus-program-to-implement-avl-tree
https://www.sanfoundry.com/cpp-program-implement-avl-trees/
https://www.geeksforgeeks.org/avl-tree-set-1-insertion/
https://www.geeksforgeeks.org/avl-tree-set-2-deletion/
And the Problem Statement is -
Write a program in C++ using AVL Tree which will have basic functions such as Insertion(), Deletion(), and Display() in a node-based AVL Tree data structure.
So its DAY 27 and the Topic is again "Binary Search Tree"
For a reference visit the following links -
https://www.programming9.com/programs/cpp-programs/136-binary-search-tree-operations-using-c
https://www.sanfoundry.com/cpp-program-implement-binary-tree-2/
https://www.geeksforgeeks.org/binary-search-tree-set-1-search-and-insertion/
https://www.geeksforgeeks.org/binary-search-tree-set-2-delete/
And the Problem Statement is -
Write a program in C++ using binary search tree which will have basic functions such as Insertion(), Deletion() and traversal functions like Preorder(), Inorder(), and Postorder() in a node based binary tree data structure.
So its DAY 26 and the Topic is "Binary Search Tree"
For a reference visit the following links -
https://www.programming9.com/programs/cpp-programs/136-binary-search-tree-operations-using-c
https://www.sanfoundry.com/cpp-program-implement-binary-tree-2/
https://www.geeksforgeeks.org/binary-search-tree-set-1-search-and-insertion/
https://www.geeksforgeeks.org/binary-search-tree-set-2-delete/
And the Problem Statement is -
Write a program in C++ using binary search tree which will have basic functions such as Insertion(), Deletion(), Searching(), and Display() in a node-based binary tree data structure.
So its DAY 25 and the Topic is "Number System/Base Conversions"
For a reference visit the following links -
https://www.robotroom.com/NumberSystems.html
And the Problem Statement is -
Write a program in C++ which will convert a number from base to another. The program should have the following conversion methods in separate functions:-
• Binary -> Decimal
• Binary -> Octal
• Binary -> Hexadecimal
• Decimal -> Binary
• Decimal -> Octal
• Decimal -> Hexadecimal
• Octal -> Binary
• Octal -> Decimal
• Octal -> Hexadecimal
• Hexadecimal -> Binary
• Hexadecimal -> Decimal
• Hexadecimal -> Octal
So its DAY 24 and the Topic is "C++ Bitwise Operators"
For a reference visit the following links -
https://www.programiz.com/cpp-programming/bitwise-operators
https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/
https://www.includehelp.com/c-programs/c-programs-bitwise-programs-and-solutions.aspx
And the Problem Statement is -
Write a program in C++ using bitwise operators which should demonstrate the basic functionalities of all the 6 bitwise operators in 6 different functions.
[NOTE: Use the 1st link to understand the basics of all the 6 bitwise operators. If want to understand more the topic and their implementation in different programs, visit the 2nd and 3rd links]
So its DAY 23 and the Topic is again "Pointers"
For a reference visit the following links -
https://www.geeksforgeeks.org/pointers-c-examples/
https://www.w3schools.com/cpp/cpp_pointers.asp
And the Problem Statement is -
Write a program in C++ using pointers which will have a function that takes a string as an argument and returns a reversed string.
So its DAY 22 and the Topic is "Loops (for, while, do-while)"
For a reference visit the following links -
https://www.programiz.com/cpp-programming/for-loop
https://www.programiz.com/cpp-programming/do-while-loop
https://www.geeksforgeeks.org/loops-in-c-and-cpp/
And the Problem Statement is -
Write a program in C++ using loops that should print a pattern (like below) when the user enters a capital letter (A-Z). (Observe the pattern carefully)
For example – If the user enters F, the program should print
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
A B B A
A B C C B A
A B C D D C B A
A B C D E E D C B A
A B C D E F F E D C B A
If the user enters J, the program should print
A B C D E F G H I J J I H G F E D C B A
A B C D E F G H I I H G F E D C B A
A B C D E F G H H G F E D C B A
A B C D E F G G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
A B B A
A B C C B A
A B C D D C B A
A B C D E E D C B A
A B C D E F F E D C B A
A B C D E F G G F E D C B A
A B C D E F G H H G F E D C B A
A B C D E F G H I I H G F E D C B A
A B C D E F G H I J J I H G F E D C B A
So its DAY 21 and the Topic is "Goto Statement"
For a reference visit the following links -
https://www.programiz.com/cpp-programming/goto
https://www.tutorialspoint.com/cplusplus/cpp_goto_statement.htm
https://www.javatpoint.com/cpp-goto-statement
And the Problem Statement is -
Write a program in C++ using goto statements that calculates the occupancy rate for a hotel in which the program will ask the user, how many floors the hotel has, and then the number of rooms on each floor and how many of them are occupied on that floor.
After that, the program should display the total number of rooms the hotel has, the total number of rooms that are occupied, the total number of rooms that are unoccupied, and the percentage of the total rooms that are occupied.
NOTE :-
It is a tradition that most hotels do not have a thirteenth floor so the program should skip the entire thirteenth floor.
Do not accept a value less than 1 for the number of floors. Do not accept a number less than 5 for the number of rooms on a floor.
So its DAY 20 and the Topic is "Math Library in C++"
For a reference visit the following links -
https://www.w3schools.com/cpp/cpp_math.asp
https://codescracker.com/cpp/cpp-mathematical-functions.htm
And the Problem Statement is -
Write a program in C++ using math library in C++, which will have the following functions :-
• A function to find All Roots of a Quadratic Equation
• A function to find Direction Ratios of a Line in an XYZ plane
• A function to find Angle Between Two Lines in an XYZ plane
• A function of an equation/theorem which you know and can code
So its DAY 19 and the Topic is again "Arrays"
For a reference visit the following links -
https://www.geeksforgeeks.org/arrays-in-c-cpp/
https://www.w3schools.com/cpp/cpp_arrays.asp
And the Problem Statement is -
Write a C++ program to Delete an Element from an Array in which a user inputs an element to delete, the element is then searched in the array, if found, it is deleted and the array is displayed and if not found, then a message “Element Not Found” is displayed.
So its DAY 18 and the Topic is "Operator Overloading"
For a reference visit the following links -
https://www.programiz.com/cpp-programming/operator-overloading
https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm
https://www.javatpoint.com/cpp-overloading
And the Problem Statement is -
Write a program in C++ use operator overloading for creating a simple calculator program having functions for addition, subtraction, multiplication, division, and modulus.
So its DAY 17 and the Topic is "Exception Handling (try, catch, throw)"
For a reference visit the following links -
https://www.w3schools.com/cpp/cpp_exceptions.asp
https://www.studytonight.com/cpp/exception-handling-in-cpp.php
And the Problem Statement is -
Write a program in C++ using exception handling in which you have to ask the user to enter the marks of a Student for subjects like English, Chemistry, ADS, and Maths. If the user exceeds the range of marks (if below 0 or above 100) in a particular subject, the program should throw an error “Invalid Marks” to the user and repeat the above processes until the use enters the correct marks. [NOTE : Try to use try{} block, catch{} block, throw() function (all of them, if possible) in your program]
So its DAY 16 and the Topic is "Friend Function"
For a reference visit the following links -
https://www.tutorialspoint.com/cplusplus/cpp_friend_functions.htm
https://www.javatpoint.com/cpp-friend-function
And the Problem Statement is -
Write a program in C++ using friend function in which you have to create a four-function calculator having a class Calculator with the following class members :-
Private:
CRadius -> float type
RLength, RBreath, RHeight -> long type
SWidth -> long type
THeight, TBase -> float type
Public:
Calculator() { CRadius=1; RLength=RBreath=RHeight=1; THeight=TBase=1; }
friend float AreaOfCircle(Calculator Ob); // To calculate Area Of Circle
friend long AreaOfRectangle(Calculator Ob); // To calculate Area Of Rectangle
friend long AreaOfSquare(Calculator Ob); // To calculate Area Of Square
friend float AreaOfTriangle(Calculator Ob); // To calculate Area Of Triangle
So its DAY 15 and the Topic is "Linked List – Queue with Array"
For a reference visit the following links -
https://www.tutorialspoint.com/cplusplus-program-to-implement-queue-using-array
https://www.geeksforgeeks.org/array-implementation-of-queue-simple/
And the Problem Statement is -
class Queue
{
int Data[10];
int Front, Rear;
public :
Queue( )
{
Front = - 1;
Rear = - 1;
}
void Add(); //to add an element into the queue
void Remove(); //to remove an element from the front of the queue
void Delete(int ITEM); //to delete all elements whose Data is equal to ITEM
};
Complete the class with all function definitions for a Circular Array Queue. Use another queue to transfer data temporarily.
So its DAY 14 and the Topic is "C++ Template"
For a reference visit the following links -
https://www.programiz.com/cpp-programming/templates
https://www.tutorialspoint.com/cplusplus/cpp_templates.htm
“ You can also go through the File Handling PPTs provided by our University “
And the Problem Statement is -
Write a program using C++ template in which you have to create a function that accepts both character type or integer type arrays, respectively, and prints the content of the array as output. [ NOTE : Use only ONE variable to accept for both the type of arrays (No two separate variables) ]
So its DAY 13 and the Topic is again "Control Statements in C++ (if-else, switch-break, loops)"
For a reference visit the following links -
https://www.geeksforgeeks.org/decision-making-c-c-else-nested-else/
https://www.geeksforgeeks.org/c-c-if-else-statement-with-examples/
https://beginnersbook.com/2017/08/cpp-if-else-statement/
And the Problem Statement is -
Write a program in C++ using control statements which will have the following functions :-
• A function to print full pyramid using “ * “
*
* * *
* * * * *
* * * * * * *
• A function to print pyramid using “ numbers “
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
• A function to print an inverted full pyramid using “ * “
* * * * * * *
* * * * *
* * *
*
• A function to print Pascal's Triangle
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
• A function to print Floyd's Triangle
1
2 3
4 5 6
7 8 9 10
So its DAY 12 and the Topic is again "File Handling"
For a reference visit the following links -
https://www.includehelp.com/cpp-programs/write-read-object-in-file.aspx (This page has a good example for reading and writing of class objects onto a file in file handling.)
https://www.includehelp.com/cpp-programs/write-read-text-in-file.aspx (This page has a good example for reading and writing of normal text onto a file in file handling.)
And the Problem Statement is -
Write a function in C++ for storing a laptop’s details in a binary file “LAPTOP.DAT” containing the objects of class LAPTOP (as defined below). The user should enter the laptop details using write() function in the file and the program should display the details of the laptop using read() function.
class LAPTOP
{
long ModelNo;
float RAM,HDD;
char Name[20];
public:
void StockEnter()
{
cout<<"\n Enter Details of the Laptop :- ";
cout<<"\n Model No. : "; cin>>ModelNo;
cout<<"\n RAM : "; cin>>RAM;
cout<<"\n HDD : "; cin>>HDD;
cout<<"\n Name : "; cin>>Name;
}
void StockDisplay()
{
cout<<"\n Details of the Laptop :- ";
cout<<"\n Model No. : "<<ModelNo;
cout<<"\n RAM : "<<RAM;
cout<<"\n HDD : "<<HDD;
cout<<"\n Name : "<<Name;
}
long ReturnModelNo()
{
return ModelNo;
}
};
So its DAY 11 and the Topic is again "Arrays"
For a reference visit the following links -
https://www.geeksforgeeks.org/arrays-in-c-cpp/
https://www.w3schools.com/cpp/cpp_arrays.asp
And the Problem Statement is -
Write a program to multiply two 3x3 matrices, where the user gives the input and the program give the output.
So its DAY 10 and the Topic is "File Handling"
For a reference visit the following links -
https://www.tutorialspoint.com/cplusplus/cpp_files_streams.htm
https://www.w3schools.com/cpp/cpp_files.asp
https://www.studytonight.com/cpp/file-streams-in-cpp.php
“ You can also go through the File Handling PPTs provided by our University “
And the Problem Statement is -
Write a program using the concepts of file handling with the following functions:
• A function to count the number of uppercase alphabets in a file
• A function to count the number of "to" and "the" in a file
• A function to count all the number of words in a file
• A function to count all the number of characters in a file
• A function which copies a file into another file
All the functions should access a file ARTICLE.TXT
So its DAY 9 and the Topic is "Linked List – Stack"
For a reference visit the following links -
https://www.geeksforgeeks.org/stack-data-structure/
https://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm
And the Problem Statement is -
Write a program (using linked list) to save the information of a city. Each node of a STACK contains the following information, in addition to pointer field:
Pin code of the city
Name of the city
TOP is a pointer that points to the topmost node of the STACK. Write the following functions:
• PUSH() – To push a node into the STACK, which is allocated dynamically.
• POP() – to remove a node from the STACK and release the memory.
So its DAY 8 and the Topic is "Conditional/Ternary Operator (exp1 ? exp2 : exp3;)"
For a reference visit the following links -
https://www.tutorialspoint.com/cplusplus/cpp_conditional_operator.htm
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c-c/
And the Problem Statement is -
Write a program that invokes a function newdate() to return an object of date type. The function newdate() takes two parameters: an object olddate of date type and number of days (int) to calculate the newdate as olddate + number of days and returns the newdate.
So its DAY 7 and the Topic is again "Classes and Objects"
For a reference visit the following links -
https://www.geeksforgeeks.org/c-classes-and-objects/
https://www.w3schools.com/cpp/cpp_classes.asp
And the Problem Statement is -
Define a class TravelPlan in C++ with the following descriptions:
Private Members:
PlanCode => of type long
Place => of type character array (string)
Number_of_travellers => of type integer
Number_of_buses => of type integer
Public Members:
• A constructor to assign initial values of PlanCode as 1001, place as "Agra", Number_of_travellers as 5, Number_of_buses as 1.
• A function NewPlan() which allows user to enter PlanCode, Plan ad Number_of_travellers. Also, assign the value of Number_of_buses as per the following conditions:
Number_of_travellers Number_of_buses
Less than 20 1
Equal to or more than 20 and less than 40 2
Equal to 40 or more than 40 3
• A function ShowPlan() to display the content of all the data members on screen.
So its DAY 6 and the Topic is "Arrays"
For a reference visit the following links -
https://www.geeksforgeeks.org/arrays-in-c-cpp/
https://www.w3schools.com/cpp/cpp_arrays.asp
And the Problem Statement is -
Suppose A, B, C are arrays of integers of size M, N, and M+N, respectively. The numbers in array A appear in ascending order while the numbers in array B appear in descending order. Write a user-defined function in C++ to produce third array C by merging arrays A and B in Ascending order. Use A, B, and C as arguments in the function.
So its DAY 5 and the Topic is "Constructor and Destructor"
For a reference visit the following links -
https://www.geeksforgeeks.org/constructors-c/ https://www.geeksforgeeks.org/destructors-c/
https://www.w3schools.in/cplusplus-tutorial/constructors-destructors/
And the Problem Statement is -
Define a class Clothing in C++ with the following descriptions:
Private Members:
• Code => of type string
• Type => of type string
• Size => of type integer
• Material => of type string
• Price => of type float
A function Calc_Price() which calculates and assign the values of GPrice as follows:
For the value of Material as "COTTON":
Type Price (Rs)
TROUSER 1500
SHIRT 1200
For Material other than "COTTON" the above-mentioned Price gets reduced by 25%.
Public Members:
A constructor to assign initial values of Code, Type, and Material with the word "NOT ASSIGNED" and Price with 0. A function Enter() to input the values of the data members Code, Type, Size, and Material and invoke the Calc_Price() function. A function Show() to display the content of all the data members for a Clothing.
So its DAY 4 and the Topic is "Pointers"
For a reference visit the following links -
https://www.geeksforgeeks.org/pointers-c-examples/ https://www.w3schools.com/cpp/cpp_pointers.asp
And the Problem Statement is -
Write a function to encode a string. The string should get converted into an unrecognizable form. [Hint: You may change the ASCII code of the constituent character by adding or subtraction a constant number from the original ASCII value of the constituent characters.]
So its DAY 3 and the Topic is "If – Else Statements"
For a reference visit the following links -
https://www.w3schools.com/cpp/cpp_conditions.asp https://www.w3schools.com/cpp/cpp_conditions_elseif.asp https://www.geeksforgeeks.org/decision-making-c-c-else-nested-else/
And the Problem Statement is -
Write a program to take input as a digit and convert it into words. (Your digit should be ranging between 0-999)
So its DAY 2 and the Topic is "Inheritance"
For a reference visit the following link -
https://www.geeksforgeeks.org/inheritance-in-c/
And the Problem Statement is -
Write a program to read and display information about employees and managers. Employee is a class that contains employee number, name, address, and department. Manager class contains all information of the employee class and a list of employees working under a manager. (Use the concept of Inheritance to complete the program)
So for today's Test Run, the Topic is "Classes And Objects"
For a reference visit the following link -
https://www.geeksforgeeks.org/c-classes-and-objects/
And the Problem Statement is -
Define a class to represent a book in a library. Include the following members: -
Data Members:
Book Number, Book Name, Author, Publisher, Price, No. of copies issued, No. of copies
Member Functions:
(i) To assign initial values
(ii) To issue a book after checking for its availability
(iii) To return a book
(iv) To display book information