-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f99458d
commit 9dc4475
Showing
1 changed file
with
50 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,74 @@ | ||
#include <iostream> | ||
#include<iostream> | ||
#include<string> | ||
#include<cctype> | ||
using namespace std; | ||
|
||
int Find_Max_Divisors(int arr[], int size); | ||
//Creating a structure and declaring variables | ||
struct record { | ||
int bookID{}; | ||
double price{}; | ||
string bookTitle{}; | ||
string bookAuthor{}; | ||
}; | ||
|
||
|
||
int main() | ||
{ | ||
int array[30]; | ||
record students[5]{}; | ||
string holder{}; | ||
|
||
for (int i = 0; i < 30; i++) { | ||
cout << "Enter number at index [" << i << "] : "; | ||
cin >> array[i]; | ||
} | ||
|
||
cout << "\nThis number has highest number of divisors : " << Find_Max_Divisors(array, 30) << endl; | ||
//Looping over to get data from the user 5 times | ||
for (int i = 0; i < 5; i++) { | ||
|
||
return 0; | ||
} | ||
cout << "Enter the book ID : "; | ||
cin >> students[i].bookID; | ||
|
||
int Find_Max_Divisors(int arr[], int size) { | ||
cout << "\nEnter the name of books author : "; | ||
cin.ignore(); | ||
getline(cin, students[i].bookAuthor); | ||
|
||
int divisor = 0, greatest = 0; | ||
cout << "\nEnter book title : "; | ||
getline(cin, students[i].bookTitle); | ||
|
||
int decider = 0; | ||
cout << "\nEnter price of the book : "; | ||
cin >> students[i].price; | ||
|
||
for (int i = 0; i < size; i++) { | ||
cout << "\n------------------------------\n\n"; | ||
} | ||
|
||
for (int j = 1; j < arr[i]; j++) { | ||
if (arr[i] % j == 0) { | ||
++divisor; | ||
} | ||
cout << "Books with same authors are : \n"; | ||
|
||
} | ||
//Looping over to find the books with same authors and displaying the titles of those books, with same authors | ||
for (int i = 0; i < 5; i++) { | ||
|
||
string str1, str2; | ||
int comma_count = 0; | ||
|
||
if (divisor > decider) { | ||
decider = divisor; | ||
greatest = arr[i]; | ||
} | ||
str1 = students[i].bookAuthor; | ||
|
||
for (int j = 0; j < 5; j++) { | ||
str2 = students[j].bookAuthor; | ||
|
||
divisor = 0; | ||
//Comparing authors throughout the array | ||
if (str1 == str2) { | ||
holder += students[j].bookTitle + ","; | ||
students[j].bookTitle.clear(); | ||
comma_count++; | ||
} | ||
|
||
} | ||
} | ||
|
||
//Comma count is being compared | ||
if (holder.length() > comma_count && comma_count > 1) { | ||
int a = holder.length() - 1; | ||
holder[a] = ' '; | ||
cout << "\nAuthor : " << str1 << "\tTitle : " << holder << "\b" << endl; | ||
} | ||
|
||
holder.clear(); | ||
|
||
return greatest; | ||
comma_count = 0; | ||
} | ||
|
||
return 0; | ||
} |