?
Solved

Assignment about STRUCT and BINARY SEARCH in C... A help will be much appreciated!

Posted on 2003-03-24
9
Medium Priority
?
261 Views
Last Modified: 2010-04-15
STRUCT ASSESSMENT

Write a program which does the following:

1. Creates a binary file with the following structure

struct person_type
{
int age;
long id;
char name[20];
};

2. Allows entry of record into the above structure
3. data entry loop to be terminated by some user action of your own choice
4. records to be saved (one at a time) into a binary file
5. creates another binary index file with the following structure -

struct index_type
{
long id;
long offset;
       };


For each record in the person file (the first file) create a record in this index file such that the id field is the same (as the record in the person file) and offset is the offset of the record in the person file. The records in the index should be sorted on id order

6. Your program should have a screen with the following capabilities:-
a. Viewing of record for any existing id that the user enters (with appropriate message if id does not exist)
b. Viewing of next record ( assuming there is already a record on the screen)
c. Viewing of previous record (assuming there is already a record on the screen)

The suer should be able to continue viewing records until he/she chooses to exit.

Access to records should be via the index file. Access to records in the index file should be via binary search

Note: The binary search algorithm only works on a sorted file

----
I'm a software development student, I'm trying to cope up with all of my subjects
I need a hand with this assignment..

Thanks a lot


lrzoom@lycos.com

0
Comment
Question by:lrzoom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Author Comment

by:lrzoom
ID: 8194471
I'm a software development student, I'm trying to cope up with all of my subjects
I need a hand with this assignment..

Thanks a lot


lrzoom@lycos.com

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8194474
Sorry, fellow. We cannot do your homework for you. If you show us your code, we maybe able to fix the errors and give some hints.

Mayank.
0
 

Author Comment

by:lrzoom
ID: 8194495
thats ok.. its good to know that u can help me fix errors n give hints thou :)

ill get started now.. thanks mayank
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:Getch
ID: 8194837
#include <stdio.h>
#include <stdlib.h>

struct person_type
{
int age;
long id;
char name[20];
} control;

void main(void) {
     extern struct person_type control;
     FILE *to_file;
     
     if ((to_file = fopen("my_file","wb")) == NULL) {
         fprintf(stderr,"%s","I can't create the file");
         exit(1);
     }
     fprintf(stdout,"%s","Enter age :");
     scanf("%d",&control.age);
     fprintf(to_file,"%d",control.age);
     fprintf(stdout,"%s","Enter id :");
     scanf("%ld",&control.id);
     fprintf(to_file,"%ld",control.id);
     fprintf(stdout,"%s","Enter name");
     scanf("%s",&control.name);
     fprintf(to_file,"%s",control.name);
    fclose(to_file);
}

this is very bad for you... but anyway i think this is correct but i'm not sure

cya getch
0
 

Expert Comment

by:Getch
ID: 8194844
this it isn't the full answer !!! only 1,2 ...think
0
 

Expert Comment

by:Getch
ID: 8194857
this algorithm it is very easy...but i'm too tired to write down :)
0
 
LVL 2

Accepted Solution

by:
bkrahmer earned 300 total points
ID: 8200938
lrzoom, if the problem is two big to carry in your head all at one time, you need to do one of two things: 1. Hash out a design using psuedocode that handles all of the requirements, and then code it.  2. Work in c++.  :)  I say this because I find it easier to stub out entire classes and their methods, and work very incrementally.  I would recommend still using object-oriented code even though you are limited to C.  Using a few structures and some clean methods it shouldn't be too difficult.

brian
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10189719
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by bkrahmer [grade B] (homework, but some good advice).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question