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
IRINA_888 [86]
2 years ago
5

Write a function searchBooks which returns ALL the books written by a specific author and return the list of the book titles as

a string, separated with comma if there are more than one titles. If these is no author in the library then return 'NOT FOUND'. Example dataset: library = [ { author: 'Bill Gates', title: 'The Road Ahead', libraryID: 1254} ];.
Computers and Technology
1 answer:
dalvyx [7]2 years ago
4 0

Answer:

var library=[{author:'Bill Gates',title:'The Road Ahead',libraryID:1254},

              {author:'Abdul Kalam',title:'India 2020',libraryID:1243},

              {author:'Abdul Kalam',title:'Ignited Minds',libraryID:1200},

              {author:'Abdul Kalam',title:'Inspiring thoughts',libraryID:1200},

              {author:'Aristotle',title:'Metaphysics',libraryID:1200}

              ];

  //author of the book to be searched

  var authorName='Abdul Kalam';

  //document.write() will write in the html page

  a=searchBooks(library,authorName);

  books=a[0];

  authorNames=a[1];

  //<h1></h1> is used to make heading Books

  document.write("Books:\n");

  for(i=0;i<books.length;i++)

      document.write(books[i]['author']+" --> "+books[i]['title']+" --> "+books[i]['libraryID']+"<br>");

  document.write("Titles:\n"+a[1]);

  function searchBooks(library,authorName){

      //empty string to assign book names

      list_of_titles='';

      books=[];

      //reading each book from 0th position to last

      for(i=0;i<library.length;i++){

          //if author is authorName then add it to list_of_titles

          if(library[i]['author']==authorName){

              books.push(library[i]);

              list_of_titles+=library[i]['title']+",";

          }

      }

      //removing the last comma

      list_of_titles=list_of_titles.slice(0,-1);

      //if list_of_titles is empty return NOTFOUND

      if(list_of_titles=='')

          return 'NOT FOUND';

      //if books are found return list_of_titles

      else

          return [books,list_of_titles];

      //returning the list of books and titles

  }

You might be interested in
Lab Goal : This lab was designed to demonstrate the similarities and differences in a for loop and a while loop.Lab Description
Mandarinka [93]

Answer:

See Explanation

Explanation:

Required:

Use for and while loop for the same program

<u>(1) String Cleaner</u>

#For Loop

name = "I am Sam"

result = ""  

<em>for i in range(0, len(name)):  </em>

<em>    if name[i]!= 'a':  </em>

<em>        result = result + name[i] </em>

print(result)

#While Loop

name = "I am Sam"

result = ""  

<em>i = 0 </em>

<em>while i < len(name): </em>

<em>    if name[i]!= 'a':  </em>

<em>        result = result + name[i] </em>

<em>    i+=1 </em>

print(result)

<u>(2): Common Divisor</u>

#For Loop

num1 = 528

num2 = 60

div = num2

if num1 > num2:

   div = num1

<em>for i in range(2,div):</em>

<em>    if num1%i == 0 and num2%i==0:</em>

<em>        print(i,end = " ")</em>

print()

#While Loop

num1 = 528

num2 = 60

div = num2

if num1 > num2:

   div = num1

i = 2

<em>while i <div:</em>

<em>    if num1%i == 0 and num2%i==0:</em>

<em>        print(i,end = " ")</em>

   i+=1

The iterates statements show the difference in the usage of both loops.

For the for loop, the syntax is:

<em>for [iterating-variable] in range(begin,end-1)</em>

<em>-------</em>

<em>---</em>

<em>--</em>

<em />

For the while loop, the syntax is:

<em>while(condition)</em>

<em>-------</em>

<em>---</em>

<em>--</em>

8 0
2 years ago
Who does Potholes effect in South Africa?
Morgarella [4.7K]
By definition, a pothole is a structure mostly located at the surface of roads and highways wherein it is usually characterised by having deep crevices which are primarily caused by extreme soil erosion or the presence of water in the area. In addition, these potholes greatly affect the transportation system of South Africa because the flow of traffic will be interrupted.
4 0
3 years ago
Given the following function definition:
neonofarm [45]

The question is incomplete! Complete question along with its step by step answer is provided below!

Question:

Given the following function definition:

void calc (int a, int& b)

{

int c;

c = a + 2;

a = a * 3;

b = c + a;

}

x = 1;

y = 2;

z = 3;

calc(x, y);

cout << x << " " << y << " " << z << endl;

What is the output of the following code fragment that invokes calc?

a. 1 2 3

b. 1 6 3

c. 3 6 3

d. 1 14 9

e. None of these

Answer:

b. 1 6 3

Explanation:

In the given problem we have a function void calc which takes two input arguments a and b and updates its values according to following equations

c = a + 2;

a = a * 3;

b = c + a;

Then we call this function calc(x,y) by providing test values of

int x = 1;

int y = 2;

int z = 3;

and the output returns the values of x, y and z

cout << x << " " << y << " " << z << endl;

Lets find out what is happening here!

When the program runs we provide x=a=1 and y=b=2

c=a+2=1+2=3

a=a*3=1*3=3

b=c+a=3+3=6

So the updated values of a=x=3 and b=y=6?

NO!

The updated values are a=x=1 and b=y=6

WHY?

There are two ways to pass values

1. Pass by values -> value cannot change  (int a)

2. Pass by reference -> value can change (int& b)

Look at the function void calc (int a, int& b) ;

Here we are passing (int a) as a value and (int& b) as a reference, therefore x remains same x=1 and y gets changed to updated value y=6 and z remains same as z=3 since it wasnt used by function calc(x,y)

The right answer is:

b. 1 6 3

x=1, y=6, z=3

4 0
3 years ago
Write a program that produces this output:
AveGali [126]

Answer:

void printC()  

{  

   int i, j;  

   for (i = 0; i < 4; i++) //i indicate row number. Here we have 5 rows

       {  

         printf("C"); //print C for every row  

         for (j = 0; j < 6; j++) //j indicate column number. Here we have 7 Rows

         {  

           if (i == 0 || i == 4) //For first and last row  

               printf("C"); //print 'CCCCCCC'

          else if (i = 1|| i= 3) //for Second forth row  

                printf("C        +      +"); //print 'C    +    +'

          else if (i = 2) For second row  

                printf("C       +++++"); //print 'C +++++'

           else

               continue; //to jump to next iteration

         }  

         printf("\n"); // print in next line

}  

}

4 0
3 years ago
Communication between a computer and a keyboard involves ______________ transmission.
4vir4ik [10]

Answer:

Simplex transmission

Explanation:

Communication between computer and keyboard involves which transmission? Answer: Simplex transmission requires communicating between a computer and a keyboard. The simple transmission & communication channel allows data from only one direction.

8 0
1 year ago
Other questions:
  • Programmers use _____ languages in the Rapid Application Development (RAD) methodology to facilitate code reuse?
    5·1 answer
  • Question: A famous Disney Movie partially takes place in this city.
    15·2 answers
  • The process of changing data from their original form to a format that more closely fits the research objectives of the research
    9·1 answer
  • Cuales Son las características de la máquina analítica de Carlos Babbage ?
    11·1 answer
  • PLEASE HELP!!!!!!!!!
    8·1 answer
  • A strategic information system can be any kind of information system that uses information technology to help an organization __
    11·1 answer
  • Why is it difficult to convince top management to commit funds to develop and implement SIS
    5·2 answers
  • What are 3 examples of a idler gear in real life?
    7·1 answer
  • The main difference between \f and \r is that \f produces a
    13·1 answer
  • ( BRAINLIEST) <br> Name 2 input devices and 2 output devices on a smart phone.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!