Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-05-2007, 08:20 PM   #1 (permalink)
Alpha Geek
 
eagle_y2j's Avatar
 
Join Date: Nov 2004
Location: Himalayas
Posts: 719
Thumbs up Help me over C project !


Can any of you check my BCA xcam project to find any bug ? I just completed this stuff using help from internet (answers) not sure are they correct or not !

Help will really be appreciated

Question 1:

Write a C program to create a calculator. The program will accept an arithmetic expression (assumed to be valid expression of only +, -, *, /, 1/x, and % operations) from the user. Evaluate the expression and display the results. Including the above functions, this calculate should provide the temporary buffer (memory function), to store and retrieve the temporary number values.

Note: You may include some features and function in your calculator program.


Code:
Ans:	#include<stdio.h>
#include<process.h>
#include<conio.h>
void main()
{
float a,b,r;
int n1,n2,r1;
char op;
clrscr();
while(1)
{
fflush(stdin);
printf("\n enter operator ");
scanf("%c",&op);
switch(op)
{
case'+':printf("\nenter value of a ");
	scanf("%f",&a);
	printf("\nenter value of b ");
	scanf("%f",&b);
	r=a+b;
	printf("\nresult=%2f",r);
	getch();
	break;
case'-':printf("\nenter value of a ");
	scanf("%f",&a);
	printf("\nenter value of b ");
	scanf("%f",&b);
	r=a-b;
	printf("\nresult=%2f",r);
	getch();
	break;
case'*':printf("\nenter value of a ");
	scanf("%f",&a);
	printf("\nenter value of b ");
	scanf("%f",&b);
	r=a*b;
	printf("\nresult=%2f",r);
	getch();
	break;
case'/':printf("\nenter value of a ");
	scanf("%f",&a);
	printf("\nenter value of b ");
	scanf("%f",&b);
	r=a/b;
	printf("\nresult=%2f",r);
	getch();
	break;
case'%':printf("\nenter value of n1 ");
	scanf("%d",&n1);
	printf("\nenter value of n2 ");
	scanf("%d",&n2);
	r1=n1%n2;
	printf("\nresult=%2d",r1);
	getch();
	break;
default:printf("\nWRONG ENTRY");
	getch();
	exit(op);
}}}

Question 2: Write a program in 'c' language to merge the contents of two binary search trees into one. Also, calculate the time and space complexities of your program?

Ans:
Code:
#include<stdio.n>
#include<conio.n>
#include<dlloc.n>
#define.TRUE1
#define FALSE 0
Struct btreenode
{Struct btreenode * leftchild;
	int data;
	struct btreenode*rightchild;
	};
void insert (struct btreenode **, int);
void delete (struct btreenode**,int);
void search (struct btreenode **, int, struct btreenode**, struct btreenode**, int*);
void inorder (struct btreenode*);
void main()
{ Struct btreenode *bt;
	int req, i=0, num, a[] = {11, 9, 13, 8, 10, 12, 14, 15, 7};
bt = NULL; /*empty tree*/
clrscr();
while (i<=8)
{insert (&bt. a[i]);
	inorder (bt);
delete (& bt. 10);
printf (“\n Binary tree after deletion:\n”);
inorder (bt);
delete (&bt, 14);
Printf (“\nBinary tree after deletion:\n”);
Inorder (bt);
Delete (&bt, 8);
Printf (“\nBinary tree after deletion:\n”);
Inorder (bt);
Delete (&bt, 13);
Printf (“\nBinary ree after deletion:\n”);
Inorder (bt);
}
/* inserts a new node in binary search tree.*\
Void insert (Struct btreenode (**Sr. Int num)
{
	if (**sr = = NULL)
	{
	*Sr = malloc (size of (struct btreenode));
		(*sr)-->leftchild = NULL);
		(*sr)--> data =num;
		(*sr) --> rightchild = NULL;
	}
	else /* Search the node to which new node will be attached*/
{
	/* If new data is less, treaverse to left*/
	if(num<(*sr) data)
		insert (&((*sr)leftchild),num);
	else
		/* else treaverse to right*/
	insert (&((*sr)rightchild),num);
	}
	}
	/* deletes a node from the binary search tree*/
	void delete (struct btreenode **root, int num)
	{
		int found;
		struct breenode * parent, *.*, *SUCC;
		/* if tree is empty*/
		if (*root == NULL)
		{
			printf (“\n Tree is empty”);
			return;
		}
		parent = X = NULL
		/* call to search function to find the node to be deleted*/
			Search (root, num, &parent, &x, &found);
		/* if the node to deleted is not found*/
			if (found == FALSE)
		{
			Printf (“\n Data to be deleted not found”);
				return;
			}
		/* if the node to be deleted has two children*/
	if (xleftchild! = NULL && x rightchild! = NULL)
	{ Parent = x;
		XSUCC = x  rightchild;
	While (xsucc  leftchild! = NULL)
	{ 	Parent = xSUCC;
		XSUCC = XSUCC  leftchild;
	}
	x--> data = XSUCC data;
	x = XSUCC;
	}
	/* if the node to be deleted has no child*/
	if (x leftchild == NULL&&x-> rightchild == NULL)
		if (parent -> rightchild == x)
		parent  rightchild = NULL;
	else
		parent -> leftchild = NULL;
		free (x);
		return;
	}
	/* if the node to be deleted has only rightchild*/
	if (x -> leftchild == NULL && x -> rightchild! = NULL)
	if (parent --> leftchild ==x)
		parent -> leftchild =x->rightchild;
	else
		parent->rightchild=x->rightchild;
	free(x);
	return;
	}
/*If the node to be deleted has only left child*/
if (x-> leftchild! = NULL && xrightchild = NULL)
if (parent->leftchild ==x)
	parent -> leftchild = x  leftchild;
else
	parent->rightchild=x ->leftchild;
	free (x)
	return;
	}}
	/* returns the address of the node to be deleted, address of its parent and whether the node is found ore not*/
void search (struct btreenode **root int num.struct btreenode ** paire, struct btreendoe, xxx int x found)
{
struct btreenode *q;
q = *root;
* found = FALSE;
*Pare = NULL;
while (q! = NULL)
{	/* if the node to be deleted is found */
	if (q data == num)
	{ *found == TRUE;
		** = q;
		return;
} * para = q;
if (q-> data > num)
q = q leftchild;
else
	q = q  rightchild;
}}
void inorder (struct btreenode.&src)
if (Src ! = NULL) }
inorder (src  leftchild);
printf (“%d\t”, src  data);
inorder (Src  rightchild);
}
}

Question 3: Write a C+program to create functions that calculate the value of Xn.
Assume that X=|=0, n=|=0.

Ans:
Code:
	#include<stdio.h>
#include<conio.h>
long int pow(int ba,int a);
void main()
{
int ba,ex,x;
long int res;
clrscr();
x:
printf("\nenter the base ");
scanf("%d",&ba);
printf("\n enter the expo ");
scanf("%d",&ex);
if(ba==0 || ex==0)
{
printf("\n base or expo should not be zero ");
goto x;
}
res=pow(ba,ex);
printf("\nresult=%d",res);
getch();
}
long int pow(int ba,int a)
{
int i;
long int r=1;
for(i=1;i<=a;i++)
r*=ba;
return r;
}
__________________
Registered LINUX USER #438929

Last edited by eagle_y2j; 05-05-2007 at 09:45 PM.
eagle_y2j is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 05-05-2007, 08:55 PM   #2 (permalink)
HELP AND SUPPORT
 
rakeshishere's Avatar
 
Join Date: Jun 2006
Posts: 1,603
Default Re: Help me over C project !

Even i am doing my BCA...Which sem does these C projects come into picture?
rakeshishere is offline  
Old 05-05-2007, 09:02 PM   #3 (permalink)
Broken In
 
Join Date: Dec 2006
Posts: 142
Default Re: Help me over C project !

hey... eagle where did you get from these source codes?!!!
prinz is offline  
Old 05-05-2007, 09:07 PM   #4 (permalink)
In The Zone
 
Join Date: Sep 2005
Posts: 416
Default Re: Help me over C project !

Just went through the first code, which looks pretty much okay!!

But why don't you compile the code and test it yourself, you will learn better that way. Post what all the errors you get, will help you to fix it.

Good luck
jack// ani is offline  
Old 05-05-2007, 09:43 PM   #5 (permalink)
Lean mean A@# kickin M/C
 
apoorv.sharma's Avatar
 
Join Date: Oct 2006
Posts: 71
Default Re: Help me over C project !

seems alright to me...did u try n run em?
__________________
It's hard to soar like an eagle when you're working with turkeys!
apoorv.sharma is offline  
Old 05-05-2007, 09:48 PM   #6 (permalink)
Alpha Geek
 
eagle_y2j's Avatar
 
Join Date: Nov 2004
Location: Himalayas
Posts: 719
Default Re: Help me over C project !

Quote:
Originally Posted by rakeshishere
Even i am doing my BCA...Which sem does these C projects come into picture?
2nd sem

I compiled them but right now can't debug due to some error ! tats y asked for help
__________________
Registered LINUX USER #438929
eagle_y2j is offline  
Old 05-05-2007, 09:54 PM   #7 (permalink)
HELP AND SUPPORT
 
rakeshishere's Avatar
 
Join Date: Jun 2006
Posts: 1,603
Default Re: Help me over C project !

Quote:
Originally Posted by eagle_y2j
2nd sem

I compiled them but right now can't debug due to some error ! tats y asked for help
Me 2 also doing some 2nd sem but have only topic on Binary search tree in the syllabus...dunno abt others?
rakeshishere is offline  
Old 05-05-2007, 10:04 PM   #8 (permalink)
Alpha Geek
 
eagle_y2j's Avatar
 
Join Date: Nov 2004
Location: Himalayas
Posts: 719
Default Re: Help me over C project !

different universities different pattern !
__________________
Registered LINUX USER #438929
eagle_y2j is offline  
Old 06-05-2007, 03:04 PM   #9 (permalink)
HELP AND SUPPORT
 
rakeshishere's Avatar
 
Join Date: Jun 2006
Posts: 1,603
Default Re: Help me over C project !

Quote:
Originally Posted by eagle_y2j
different universities different pattern !
yup..mine is BU
rakeshishere is offline  
Old 06-05-2007, 03:44 PM   #10 (permalink)
* Teh Flirt King *
 
Quiz_Master's Avatar
 
Join Date: Dec 2005
Location: Originally From : Ratlam M.P., Currently in: Hyderabad
Posts: 972
Default Re: Help me over C project !

^^ Ghurrr...
And in our university all they teach is PASCAL . Cr@p...

C and C++ is in 3 and 4 th sem.
I am too in 2nd sem.

I am in Vikram University Ujjain...MP.

ANd yeah, first code seems perfectly OK to me..
But in second code I am having problems compiling it.
__________________
World is just a Quizzical Reality : Quiz_Master//Ashwin :D

Blog: http://ashwinsaxena.com/blog - Tech, Life and Other Things.
Quiz_Master is offline  
Old 06-05-2007, 11:10 PM   #11 (permalink)
In The Zone
 
webgenius's Avatar
 
Join Date: Oct 2006
Posts: 394
Default Re: Help me over C project !

Looks like you haven't computed the complexity in the 2nd program.
The best way to approach the 2nd program is to strip both the trees. You'll get a set of integers. Now start constructing the tree using these integers.
webgenius is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Good Project in PHP for my college project debiprasad_sahoo Open Source 8 15-12-2006 05:31 PM
Help in project nitish_mythology QnA (read only) 3 28-11-2005 12:55 PM
Project IGI [Project Repair] upendra_gp Gamerz 6 12-06-2005 09:28 AM

 
Latest Threads
- by topgear
- by abhidev
- by clmlbx
- by Sarath

Advertisement




All times are GMT +5.5. The time now is 05:21 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2