Question

8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10 234561 345612 Java Quantity 20 The get_info function must ask the user how many books to enter and then input that number of books into the array and return to main. The display info function displays all of the books from the array. The array of structures (created in main) must be passed to both functions (other parameters may also be required). Both functions must be called from main (i.e, do not call one function from the other). Use pointer notation to access elements of the array in the get info function and array notation in the display_info function. Assume that the book name is no longer than 30 characters and the size of the database is up to 200 books Bonus: (2 marks) In the end of main) store the database to a file called library.txt
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<dos.h>

#include<graphics.h>

  

  

union REGS i,o;

main()

{

int gd=DETECT,gm,maxx,maxy,x,y,button;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

maxx=getmaxx();

maxy=getmaxy();

rectangle(0,56,maxx,maxy);

setviewport(1,57,maxx-1,maxy-1,1);

gotoxy(26,1);

printf("MouseDemostration program");

if(initmouse()==0)

{

closegraph();

restorecrtmode();

printf("\n mouse driver not loaded");

exit(1);

  

}

restrictmouseptr(1,57,maxx-1,maxy-1);

showmouseptr();

gotoxy(1,2);

printf("Left button");

gotoxy(15,2);

printf("Right button");

gotoxy(55,3);

printf("press anaykey to exit");

while(!kbhit())

{

getmousepos(&button,&x,&y);

gotoxy(5,3);

(button&1)==1?printf("down"):printf("up");

gotoxy();

(button&2)==2?printf("Down"):printf("Up");

gotoxy(65,2);

printf("X=%03d y=%03d",x,y );

}

return;

}

initmouse()

{

i.x.ax=0;

int86(0x33,&i,&o);

return(o.x.ax);

}

showmouseptr()

{

i.x.ax=1;

int86(0x33,&i,&o);

return;

}

  

restrictmouseptr(int x1,int y1,int x2,int y2)

{

i.x.ax=7;

i.x.cx=x1;

i.x.dx=x2;

int86(0x33,&i,&o);

i.x.ax=8;

i.x.cx=y1;

i.x.dx=y2;

int86(0x33,&i,&o);

return;

}

getmousepos(int *button,int *x,int *y)

{

i.x.ax=3;

int86(0x33,&i,&o);

*button=o.x.bx;

*x=o.x.cx;

*y=o.x.dx;

return;

}

Add a comment
Know the answer?
Add Answer to:
8. (15 marks) Write a complete C program, which uses an array of structures and two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • Write a console-based program ( C # ) that asks a user to enter a number...

    Write a console-based program ( C # ) that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • Write a C++ program that dynamically allocates an array large enough to hold a user-defined number...

    Write a C++ program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible. Input Validation: Do not accept negative numbers for...

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • Write a complete C++ program that will: Declare a vector of integers Use a pointer to...

    Write a complete C++ program that will: Declare a vector of integers Use a pointer to dynamically allocate an array of 10 elements Ask the user how many values they would like to have in the data structures Read in the user’s response and make sure that it is greater than 20 (error loop) Generate the number of integers that the user asked for and store them into both data structures. The integer values should be unique unordered values (no...

  • (C++ Program) 1. Write a program to allow user enter an array of structures, with each...

    (C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • read it carefully C++ Question: Write a program that dynamically allocates an array large enough to...

    read it carefully C++ Question: Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible. Input Validation: Do not...

  • Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the...

    Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the user to enter a number and based on the entered number it allocates the array size. Then based on that number it asks the user that many times to enter student’s names. What you need to do:  Add another array of doubles to store the gpa of each student as you enter them  You need to display both the student’s name and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT