1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
motikmotik
2 years ago
5

Develop a program to sort a file consisting of bonks details in the alphabetical order of author names. The details of books inc

lude book id, author_name, price. no of pages, publisher, year of publishing
Please provide C++ program for above question.​
Computers and Technology
1 answer:
olga2289 [7]2 years ago
6 0

Use the knowledge in computational language in C++ to write the a code with alphabetical order of author name.

<h3>How to define an array in C++?</h3>

An Array is a set of values ​​arranged in lists and accessible through a positive numeric index. So, we have that each position of our Array is a variable of the type of our Array, so we have to have a way to initialize this set of variables.

<em>#include <iostream></em>

<em>#include <iomanip></em>

<em>#include <fstream></em>

<em>#include <string></em>

<em>using namespace std;</em>

<em>struct Book {</em>

<em>    string title;</em>

<em>    string author;</em>

<em>};</em>

<em>const int ARRAY_SIZE = 1000;</em>

<em>Book books [ARRAY_SIZE];</em>

<em>string pathname;</em>

<em>ifstream library;</em>

<em>int LoadData();</em>

<em>void ShowAll(int count);</em>

<em>void ShowBooksByAuthor(int count, string name);</em>

<em>void ShowBooksByTitle(int count, string title);</em>

<em>void sortByTitle(int count, string title);</em>

<em>void sortByAuthor(int count, string author);</em>

<em>int main()</em>

<em>{   </em>

<em>    int count = 0;</em>

<em>    char selector = 'q', yesNoAnswer = 'n';</em>

<em>    string name;</em>

<em>    string title;</em>

<em>      cout << "Welcome to Forrest's Library Database." << endl;</em>

<em>    cout << "Please enter the name of the backup file: ";</em>

<em>    getline(cin, pathname);</em>

<em>    LoadData();</em>

<em>    count = LoadData();</em>

<em>    cout  << count << " records loaded successfully." << endl;</em>

<em>    do </em>

<em>    {</em>

<em>        cout << endl << "\t(S)how All, Search (A)uthor, Search (T)itle, (Q)uit: "; </em>

<em>        cin >> selector;</em>

<em>        selector = toupper(selector);</em>

<em>        switch(selector)</em>

<em>        {</em>

<em>            case 'S': </em>

<em>                sortByTitle(count, title);</em>

<em>                if (count <= 0)</em>

<em>                    cout << "No counts found!\n";</em>

<em>                else</em>

<em>                    ShowAll(count);</em>

<em>                break;</em>

<em>            case 'A': </em>

<em>                sortByAuthor(count, name);</em>

<em>                cout << "bookAuthor: ";</em>

<em>                cin.ignore();</em>

<em>                getline(cin, name);</em>

<em>                if (count <= 0)</em>

<em>                    cout << "No records found!\n";</em>

<em>                else</em>

<em>                    ShowBooksByAuthor(count, name); </em>

<em>                break;</em>

<em>            case 'T': </em>

<em>                sortByTitle(count, title);</em>

<em>                cout << "bookTitle: ";</em>

<em>                cin.ignore();</em>

<em>                getline(cin, title);</em>

<em>                if (count <= 0)</em>

<em>                    cout << "No records found!\n";</em>

<em>                else</em>

<em>                    ShowBooksByTitle(count, title);      </em>

<em>                break; </em>

<em>        }</em>

<em>    }</em>

<em>    while (selector != 'q' && selector != 'Q'); </em>

<em>    return 0;</em>

<em>}</em>

<em>int LoadData() </em>

<em>{</em>

<em>    int count = 0;</em>

<em>    int i = 0;</em>

<em>    library.open(pathname);</em>

<em>    ifstream library(pathname);</em>

<em>    if (!library)</em>

<em>    {</em>

<em>        cout << "Cannot open backup file" << endl;</em>

<em>        return 0;</em>

<em>    }</em>

<em>    while (!library.eof())</em>

<em>    {</em>

<em>        getline(library, books[count].title);</em>

<em>        getline(library, books[count].author);</em>

<em>        count++;</em>

<em>    }</em>

<em>    return count;</em>

<em>}</em>

<em>void ShowAll(int count) </em>

<em>{</em>

<em>    for (int i = 0; i < count; i++)</em>

<em>    {</em>

<em>       cout << books[i].title << " " << "(" << books[i].author << ")" << endl;</em>

<em>    }</em>

<em>}</em>

<em>void ShowBooksByAuthor(int count, string name) </em>

<em>{</em>

<em>    int j = 0;</em>

<em>    for (int i = 0; i < count; i++)</em>

<em>    {</em>

<em>        if(books[i].author.find(name) < 100) </em>

<em>        {</em>

<em>            cout << books[i].title << " " << "(" << books[i].author << ")" << endl;</em>

<em>            j++;</em>

<em>        }</em>

<em>    }</em>

<em>    cout << j << " records found";}</em>

<em>void ShowBooksByTitle(int count, string title) </em>

<em>{</em>

<em>    int j = 0;</em>

<em>    for (int i = 0; i < count; i++)</em>

<em>    {</em>

<em>        if(books[i].title.find(title) < 100)</em>

<em>        {</em>

<em>            cout << books[i].title << " " << "(" << books[i].author << ")" << endl;</em>

<em>            j++;</em>

<em>        }</em>

<em>    }</em>

<em>    cout << j << " records found";</em>

<em>}</em>

<em>void sortByTitle(int count, string title) {</em>

<em>    string temp;</em>

<em>    for (int i = 0; i < count; i++) {</em>

<em>        for(int j = 0; j < count - i; j++) {</em>

<em>            if (books[j].title > books[j + 1].title) {</em>

<em>                temp = books[j].title;</em>

<em>                books[j].title = books[j + 1].title;</em>

<em>                books[j + 1].title = temp;</em>

<em>            }</em>

<em>        }</em>

<em>    }</em>

<em>}</em>

<em>void sortByAuthor(int count, string name) {</em>

<em>    string temp;</em>

<em>    for (int i = 0; i < count; i++) {</em>

<em>        for(int j = 0; j < count - i; j++) {</em>

<em>            if (books[j].author > books[j + 1].author) {</em>

<em>                temp = books[j].author;</em>

<em>                books[j].author = books[j + 1].author;</em>

<em>                books[j + 1].author = temp;</em>

<em>            }</em>

<em>        }</em>

<em>    }</em>

<em>}</em>

See more about C++ at brainly.com/question/19705654

You might be interested in
The device that links computers via communication lines is called the:
m_a_m_a [10]
The device is ; a modem.
Hope this helps

7 0
3 years ago
The Solution Explorer window ____.
nataly862011 [7]

Answer:

The correct answer for the given question is option(d).

Explanation:

Solution Explorer is found in Microsoft Visual Studio.When we create a project in the c# or another programming language the solution explorer window is used. The Solution Explorer takes care of the projects and files.  

Solution Explorer displays an overall view of the current project. In the Solution Explorer we can delete or add the file in the project. The  Solution Explorer window displays the list that is contained in the current solution.

  • Option(a),Option(b) and Option(c) are the incorrect option for the Solution Explorer window.
  • So, Option(d) is the correct answer for the solution explorer.
8 0
2 years ago
Climatologist use weather balloons, stethoscopes, and satellites true or false
Nonamiya [84]

Answer:

False.

Explanation:

A stethoscope is a medical instrument which is used for listening to the work of the heart and lungs.  It consists of a microphone that rests on the patient's chest, and rubber tubes that bring the sound to the earphones. An ordinary stethoscope does not have any moving or electrical parts, as it only mechanically conducts sound from the patient's chest to the doctor's ear.   One of the simplest examinations that doctors perform today is listening to the lungs and heart with a stethoscope. With the help of this instrument, noises are heard during the work of the lungs and heart.

8 0
2 years ago
Edhesive intro to CompSci Test 7 answers pls
algol13

Answer:

nothing

Explanation:

nothing

6 0
2 years ago
Write a program and flowchart. The program should ask the user for the average temperature in each of the last 12 months. After
Afina-wow [57]

#First we define the variables to house the temperatures

#temp is an empty array that will be used to store the temperature

Temp = []

#The months is defined as stated below

months = 12

#Ask the user for the temperature input and unit if possible

print("Kindly enter the temperature here")

#the program enter loop to get the temperatures.

for x in range(months):  

   InitTemp = str(input("Kindly add the unit behind the number .eg C for celcius"))

   Temp.append(InitTemp)

j=0

for x in range(len(Temp)):  

   j=j+1

   print("The Temperature is", " ", Temp[x], "for the ", j, "Month" )

#there is an attached photo for the flowchart

5 0
2 years ago
Other questions:
  • You have a Nano Server named Nano1. Which cmdlet should you use to identify whether the DNS Server role is installed on Nano1
    12·1 answer
  • Which type of JPEG image records the most information in the digital file? Medium Low Fine Expert
    6·2 answers
  • Advertising is organized around four distinct groups. The _____ group includes the photographers, the illustrators, video produc
    9·1 answer
  • Most Internet users access commercial websites, which have higher-quality information because of higher editing standards and th
    12·1 answer
  • The computer output for integer programs in the textbook does not include reduced costs, dual values, or sensitivity ranges beca
    14·1 answer
  • ____ is a method of querying and reporting that takes data from standard relational databases, calculates and summarizes the dat
    11·1 answer
  • Organizing speech ideas according to physical space, direction, or location calls for a _____ organizational pattern.
    11·1 answer
  • A hardware compatibility list recommends striping with double parity as storage for an application. In a test environment, a tec
    13·1 answer
  • Subscribe too my you tube channel for a brainiest
    15·1 answer
  • Which benefit does the Cloud provide to start-up companies without access to large funding?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!