Little help here

I have no idea how to delete and edit the records of the students.

Page 1 of 1

8 Replies - 504 Views - Last Post: 17 July 2010 - 02:27 PM Rate Topic: -----

#1 hailfall  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 54
  • Joined: 05-February 10

Little help here

Posted 17 July 2010 - 10:45 AM

I have no idea how to delete and edit the records of the students.

#include<stdio.h>

#define MAX 20

typedef struct list
	{
		char n[19][21];
		int q1[19],q2[19],q3[19];
		float ave[19];
		int id[19], last;
	} REC;

REC x;

void makenull();
void insert();
void display(int k);
int menu();
void compav();
void SIDnumber();

void main()
{

	int SID;

	SIDnumber();
	makenull();
	begin:
	clrscr();
	while(1){
		switch(menu()){
			case 1: clrscr(); gotoxy(20,2); printf("-INSERT MODE-");
					  insert(); break;
				case 2: clrscr(); compav(); gotoxy(20,2); cprintf("-DISPLAY MODE-");
					gotoxy(1,2); cprintf("\n\nEnter ID number: "); cscanf("%d",&SID);
					display(SID); clrscr(); break;
				case 3: exit(0); break;
			       default: printf("\nInvalid Input\n\n");getch(); goto begin;
				}
		}
}

void makenull()
{
	x.last=-1;
}

void insert()
{
	if(x.last >= MAX-1)
	{
		gotoxy(20,6);
		cprintf("\nThe List is FULL");
		gotoxy(20,16);
		getch();
	}
	else {
	gotoxy(1,6);
	cprintf("Enter your Name: ");
	gets(x.n[x.last+1]);
	cprintf("\n\nEnter Quiz1: ");
	cscanf("%d", &x.q1[x.last+1]);
	cprintf("\n\nEnter Quiz2: ");
	cscanf("%d", &x.q2[x.last+1]);
	cprintf("\n\nEnter Quiz3: ");
	cscanf("%d", &x.q3[x.last+1]);
	getchar();
	gotoxy(1,15);
	cprintf("ID NUMBER: ");
	cprintf("%d",x.id[x.last+1]);
	getchar();
	}
	x.last++;
	clrscr();


}

void display(int k)
{
	int i, a = 0;
	char *n[]={"Name","Quiz1","Quiz2","Quiz3","Average"};

	if(x.last==-1){
		gotoxy(5,5);
		cprintf("\n\nNo Record stored yet!");
		getch();
		}
	else {
		gotoxy(1,6);
		cprintf("%s",n[0]);
		for(i=1;i<=4;i++)
		{
			gotoxy(22+a,6);
			cprintf("%s", n[i]);
			a = a+10;
		}
		gotoxy(1,8);
		cprintf("%s", x.n[k-191]);
		gotoxy(22,8);
		cprintf("%d",x.q1[k-191]);
		gotoxy(32,8);
		cprintf("%d",x.q2[k-191]);
		gotoxy(42,8);
		cprintf("%d",x.q3[k-191]);
		gotoxy(52,8);
		cprintf("%5.2f",x.ave[k-191]);
		getchar();

	}

}

void compav()
{
	int a;
	for(a=0;a<=x.last;a++)
	{
		x.ave[a]=(x.q1[a]+x.q2[a]+x.q3[a])/3.0;
	}
}

void SIDnumber()
{
	int i=0;
	while(i<=19)
	{
		x.id[i]=191+i;
		i++;
	}
}


int menu()
{
	char *m[]={"SELECTION","Insert","Display","Exit"};
	int x,i;
	gotoxy(20,2);
	cprintf("---%s---",m[0]);
	for(i=1;i<=3;i++)
	{
		gotoxy(10,4+i);
		cprintf("%d.) %s",i,m[i]);
	}
	gotoxy(10,10);
	cprintf("Select Numbers (1-3): ");
	cscanf("%d",&x);
	clrscr();
	return x;
}



MOD EDIT: Added the question to the post.

This post has been edited by JackOfAllTrades: 17 July 2010 - 10:50 AM
Reason for edit:: Added code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: Little help here

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Little help here

Posted 17 July 2010 - 10:49 AM

When you're posting code, use code tags. :code: You've been here long enough to know that. You've ALSO been here long enough to actually ask a question, not put a stupid title ("Little Help Here"), a wall of horrible code probably written for a 20-year-old compiler, and NO FREAKING QUESTION!!!

EDIT: Oh wait, you put it into the description of the post. Next time, put it IN the post, please.

Hope you're not expecting us to finish your homework for you.

This post has been edited by JackOfAllTrades: 17 July 2010 - 10:52 AM

Was This Post Helpful? 0
  • +
  • -

#3 jnz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-June 10

Re: Little help here

Posted 17 July 2010 - 10:52 AM

What is the question?
Was This Post Helpful? 0
  • +
  • -

#4 hailfall  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 54
  • Joined: 05-February 10

Re: Little help here

Posted 17 July 2010 - 10:53 AM

I am very sorry sir, sir do you have idea how to put a function that locate my character in struct and then edit or delete it?
Was This Post Helpful? 0
  • +
  • -

#5 laserbeak43  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 134
  • Joined: 07-November 09

Re: Little help here

Posted 17 July 2010 - 11:03 AM

i bet if your code were documented better or your variables named cleaner, you wouldn't have this issue.
Was This Post Helpful? 0
  • +
  • -

#6 hailfall  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 54
  • Joined: 05-February 10

Re: Little help here

Posted 17 July 2010 - 11:12 AM

any idea adding functions for editing and deleting students records?
Was This Post Helpful? 0
  • +
  • -

#7 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Little help here

Posted 17 July 2010 - 12:18 PM

To that program... no not really... I am not even sure that program does anything of any use anyway.

I mean I guess you will increase x.last, and then set the values of x.name[last], x.q1[last], x.q2[last], x.q3[last] etc.

However the program is not really maintainable and I would not touch it myself.
Was This Post Helpful? 0
  • +
  • -

#8 hailfall  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 54
  • Joined: 05-February 10

Re: Little help here

Posted 17 July 2010 - 12:38 PM

is there any other way sir?
Was This Post Helpful? 0
  • +
  • -

#9 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Little help here

Posted 17 July 2010 - 02:27 PM

rewrite the program?

I mean sure there are other ways, but I really don't ant to dive into the program to figure them out, basically you just need to add an element into the array. the "last" member seems to keep track of the insertion point, so I think the easiest way I described already.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1