Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ignore parts b and c of the exercise in the text book. Assume that we will have

ID: 3856505 • Letter: I

Question

Ignore parts b and c of the exercise in the text book.

Assume that we will have up to 500 authors.

For part a),store the author's name, number of books written and target reader age in three separate parallel arrays. Then, write separate loops and other code required to:

displays each author's name, the number of books he/she has written and the target reader age

calculate and display the total number of books written

calculate and display the average number of books written by all authors

calculate and display the average target reader age

allow the user to enter an author's name, then search for that name and display how many books that author has written and his/her target reader age

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct author
{
char name[50];
int books;
int target_age;
};

void main()
{
clrscr();
int flag=1,count=0,i,totalbook=0,totalreader=0;
char searchname[50];
author obj[500];
while(flag==1)
{
cout<<"enter the name ;";
gets(obj[count].name);
cout<<"enter the no of books written :";
cin>>obj[count].books;
cout<<"enter the target age :";
cin>>obj[count].target_age;
cout<<" do you want to enter more(press 1 for more and 0 to exit) :";
cin>>flag;
count++;
};
for(i=0;i<count;i++)
{
cout<<"name is :";
puts(obj[i].name);
cout<<"no of books written : ";
cout<<obj[i].books;
cout<<"target age is ; ";
cout<<obj[i].target_age;
}
for(i=0;i<count;i++)
{
totalbook+=obj[i].books;
cout<<" total no books are :"<<totalbook;
}

float avgbook=totalbook/count;
cout<<" average no of books written by all the author is : "<<avgbook;

for(i=0;i<count;i++)
{
totalreader+=obj[i].target_age;

}

float avgreader=totalreader/count;
cout<<" average target age of all the author is : "<<avgreader;

cout<<"enter the author name";
gets(searchname);

for(i=0;i<count;i++)
{
if(strcmp(obj[i].name,searchname))
{ cout<<"no of books written : ";
cout<<obj[i].books;
cout<<"target age is ; ";
cout<<obj[i].target_age;

}
}

getch();
}