Posts

Showing posts from August, 2023

205: Book Catalog: Define a struct to represent a book with attributes like title, author, and publication year. Write a program to create a catalog of books by taking user input and display books published after a certain year.

  // Book Catalog: Define a struct to represent a book with attributes like title, author, and publication year. // Write a program to create a catalog of books by taking user input and display books published after a certain year. #include < iostream > using namespace std ; struct Books {     string title , author ;     int year ; }; Books new_book (); void print_book ( int i , Books x []); int main () {     int num ;     cout << " Enter the total number of books: " ;     cin >> num ;     // const int total = num;     Books book [ num ];     for ( int i = 0 ; i < num ; i ++)     {         book [ i ] = new_book ();     }     system ( " cls " );     int year ;     cout << " Enter the year: " ;     cin >> year ;     cout << " \n Every book published ...

204: Employee Database: Create a struct to store information about an employee, including name, employee ID, and salary. Write a program to input data for a group of employees and display the employee with the highest salary.

  // Employee Database: Create a struct to store information about an employee, including name, employee ID, and salary. // Write a program to input data for a group of employees and display the employee with the highest salary. #include < iostream > using namespace std ; struct Employee {     string name , employee_id ;     int salary ; }; Employee enter_employee (); void print_employee ( int x , Employee y []); int main () {     int num ;     cout << " Enter the total number of students: \n " ;     cin >> num ;     const int total = num ;     Employee employee [ total ];     for ( int i = 0 ; i < total ; i ++)     {         employee [ i ] = enter_employee ();     }     system ( " cls " );     cout << " The employee with highest salary is: " ;     int j = 0 ;     for...

203: Rectangle Area: Define a struct to represent a rectangle with attributes length and width. Write a program to calculate and display the area of a given rectangle.

  // Rectangle Area: Define a struct to represent a rectangle with attributes length and width. // Write a program to calculate and display the area of a given rectangle. #include < iostream > using namespace std ; struct Rectangle {     int length , width ; }; Rectangle add_rect (); int main () {     Rectangle rect1 = add_rect ();     Rectangle rect2 = add_rect ();     Rectangle rect3 = add_rect ();     system ( " cls " );     cout << " Area of rectangle 1 is: " << rect1 . length * rect1 . width << endl ;     cout << " Area of rectangle 2 is: " << rect2 . length * rect2 . width << endl ;     cout << " Area of rectangle 3 is: " << rect3 . length * rect3 . width << endl ;     return 0 ; } Rectangle add_rect () {     system ( " cls " );     Rectangle x ;     cout << " ...

202: Student Record: Create a struct to represent a student with attributes like name, roll number, and marks in different subjects. Write a program to input details of multiple students and display their information.

// Student Record: Create a struct to represent a student with attributes like name, roll number, and marks in different subjects. // Write a program to input details of multiple students and display their information. #include < iostream > using namespace std ; struct Student {     string name , roll_num ;     int bio_marks , phy_marks , comp_marks ; }; Student New_Student (); template < typename T > T input ( string x ); string input_string ( string x ); void show_student_data ( Student x ); int main () {     Student s1 = New_Student ();     Student s2 = New_Student ();     Student s3 = New_Student ();     system ( " cls " );         show_student_data ( s1 );     cout << endl ;     show_student_data ( s2 );     cout << endl ;     show_student_data ( s3 );     cout << endl ;     return 0 ; ...

201: Find and print first repeating element in array

  // Find and print all unique elements of a given array of integers #include < iostream > using namespace std ; int main () {     int size ;     cout << " Enter the size of array: " ;     cin >> size ;     int array [ size ];     for ( int i = 0 ; i < size ; i ++)     {         cout << " Enter a string for index " << i << " : " ;         cin >> array [ i ];     }     system ( " cls " );     cout << " First repeating element is: " ;     for ( int i = 0 ; i < size ; i ++)     {         for ( int j = i + 1 ; j < size ; j ++)         {             if ( array [ i ] == array [ j ])             {               ...

200: Find and print all unique elements of a given array of integers

  // Find and print all unique elements of a given array of integers #include < iostream > using namespace std ; int main () {     int size ;     cout << " Enter the size of array: " ;     cin >> size ;     int array [ size ];     for ( int i = 0 ; i < size ; i ++)     {         cout << " Enter a string for index " << i << " : " ;         cin >> array [ i ];     }     system ( " cls " );     cout << " All unique elements of array are: " ;     for ( int i = 0 ; i < size ; i ++)     {         int count = 0 ;         for ( int j = 0 ; j < i ; j ++)         {             if ( array [ i ] == array [ j ])             { ...

199: Find the number of pairs of integers in a given array of integers whose sum is equal to a specified number

  // Find the number of pairs of integers in a given array of integers whose sum is equal to a specified number #include < iostream > using namespace std ; int main () {     int size ;     cout << " Enter the size of array: " ;     cin >> size ;     int array [ size ];     for ( int i = 0 ; i < size ; i ++)     {         cout << " Enter a string for index " << i << " : " ;         cin >> array [ i ];     }     int num ;     cout << " Enter a number: " ;     cin >> num ;     system ( " cls " );     cout << " Array elements pair whose sum = " << num << ' : ' ;     for ( int i = 0 ; i < size ; i ++)     {         for ( int j = i + 1 ; j < size ; j ++)    ...

198: Write a C++ program to find the third largest string in a given array of strings.

  // Write a C++ program to find the third largest string in a given array of strings. #include < iostream > using namespace std ; int main () {     int size ;     cout << " Enter the size of array: " ;     cin >> size ;     string array [ size ];     for ( int i = 0 ; i < size ; i ++)     {         cout << " Enter a string for index " << i << " : " ;         getline ( cin >> ws , array [ i ]);     }     system ( " cls " );     for ( int i = 0 ; i < size ; i ++)     {         for ( int j = i + 1 ; j < size ; j ++)         {             if ( array [ i ]. length () < array [ j ]. length ())             {               ...

197: Find the next greater element of every element of a given array of integers

  // Find the next greater element of every element of a given array of integers #include < iostream > using namespace std ; int main () {     int size ;     cout << " Enter the size of array: " ;     cin >> size ;     int array [ size ];     for ( int i = 0 ; i < size ; i ++)     {         cout << " Enter a number for index " << i << " : " ;         cin >> array [ i ];     }     system ( " cls " );     cout << " List of next more powerful element is: \n " ;     for ( int i = 0 ; i < size ; i ++)     {         for ( int j = i + 1 ; j < size ; j ++)         {             if ( array [ i ] < array [ j ])             {       ...

196: Find the most occurring element in an array of integers

  // Find the most occurring element in an array of integers #include < iostream > using namespace std ; int main () {     int size ;     cout << " Enter the size of array: " ;     cin >> size ;     int array [ size ];     for ( int i = 0 ; i < size ; i ++)     {         cout << " Enter a number for index " << i << " : " ;         cin >> array [ i ];     }     system ( " cls " );     cout << " Most frequent occuring element is: " ;     int max = 0 ;     for ( int i = 0 ; i < size ; i ++)     {         int count = 0 ;         for ( int j = i + 1 ; j < size ; j ++)         {             if ( array [ i ] == array [ j ])     ...

195: Find all elements in array of integers which have at-least two greater

  // C++ Exercises: Find all elements in array of integers which have at-least two greater elements #include < iostream > using namespace std ; int main () {     int size ;     cout << " Enter the size of array: " ;     cin >> size ;     int array [ size ];     for ( int i = 0 ; i < size ; i ++)     {         cout << " Enter a number for index " << i << " : " ;         cin >> array [ i ];     }     system ( " cls " );     cout << " All numbers having atleast two greater elements are: " ;     for ( int i = 0 ; i < size ; i ++)     {         int count = 0 ;         for ( int j = i + 1 ; j < size ; j ++)         {             if ( array [ i ] < a...

194: Write a program in C++. In this program you have to declare 2-D array of size 7x7 having type as integer. Populate this array with user input values and then display the sum of all the left diagonal entries in this array.

  // Write a program in C++. In this program you have to declare 2-D array of size 7x7 having type as integer. // Populate this array with user input values and then display the sum of all the left diagonal entries in this array. #include < iostream > using namespace std ; int main () {     int r_size , c_size ;     cout << " Enter the size of rows: " ;     cin >> r_size ;     cout << " Enter the size of column: " ;     cin >> c_size ;     int array [ r_size ][ c_size ];     for ( int i = 0 ; i < r_size ; i ++)     {         for ( int j = 0 ; j < c_size ; j ++)         {             cout << " Enter element in row index " << i << " and column index " << j << " : " ;             cin >> array [ i ][ j...