Education Menu

 

Features Menu

 

Additional Menu

 

Now Online

We have 145 guests online
 

@edulanka

 

Follow US

Twitter You Tube Google Plus
Pinterest Facebook EduLanka Blog

 

Information Zone

eduLanka Sinhala

Welcome to eduLanka.LK, Largest online education web site in Sri Lanka & most popular educational web site among Sri Lankan students. EduLanka, Best nonprofit & educational website is provided large numbers of online lessons, education related course information, teachers information, E books, examination result alerts, goverment job alerts, tuition class information, career guide for school leavers and more resources related to education in Sri Lanka. Edulanka provides education related resources from primary education, O-Level & A-Level education, University & Postgraduate education and vocational training education.

EduLanka IDN Domains http://එඩියුලංකා.ලංකා http://எடியுலங்கா.இலங்கை


jobs Mathematics SLAS Exam Dharma Education Results



 

Inside Online School

Share Us

Home Page Information Technology C, C++ and C# Programing (C වැඩසටහන්කරණය)

Lined List C - Accounting Program
Thursday, 09 September 2010 14:23

Linked List Based Accounting Program in C programing Language

Linked List and Array can be use to develop simple programs in C programing Language. Here we are produced important and goog program in Accounting in Linked list C program.

 

Linked List අමාරුද? මෙන්න C programing Language යොදාගනිමින් නිර්මාණය කල වැඩසටහනක්.........

 


 

/* http://www.edulanka.lk */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

මෙම කොටසින් කරනුයේ වැඩසටහනට අදාල Libraries import කරගැනීමයි.

struct NODE {
char *name;
int number;
float balance;
struct NODE *next;
};

ලිස්ට් එකක් සෑදීමේදී නෝඩ් එක සකස්කර ගැනීම සිදුකරයි.

/* implementation of Prototype */
void add_acc(struct NODE *llist, int num, float bal, char acc_name[64]);
void del_acc(struct NODE *llist, int num);
void display_list(struct NODE *llist, int num);
void diposit(struct NODE *llist, int num, float amt);
void withdraw(struct NODE *llist, int num, float amount);
int  search_value(struct NODE *llist, char name[64]);

භිවිතා කීරීමට බලාපොරොත්තු වත functions ‍හදුන්වාදෙයි.

// Defining Global variables
int main(void) {
int num = 0;
float bal = 0;
int choice = 1;
int find = 0;
float amt;
float amount;
char name[64];
struct NODE *llist;
විචල්‍යයන් හදුන්වාදෙයි.

llist = (struct NODE *)malloc(sizeof(struct NODE));
llist->number = 0;
llist->balance = 0;
llist->next = NULL;

/* Main Menu */
while(choice != 0) {
printf("\n ========================================\n");
printf("\n  www.edulanka.lk \n");
printf("  eduLanka online education website of Sri Lanka\n\n");

printf("  1) Add Account\n");
printf("  2) Delete Account\n");
printf("  3) Diposit \n");
printf("  4) Withdraw \n");
printf("  5) Search Account by Name\n");
printf("  6) Display Account Infomation\n\n");
printf("  9) Exit Program\n");

printf("\n ========================================\n");
printf("\n  Choose your option : ");

scanf("%d", &choice);
printf("\n ========================================\n");



/* Main Menu Tasks */
switch(choice) {

case 1:
printf(" Add Accounts\n");
printf(" ------------------------\n");
printf(" Enter the Account Number: ");
scanf("%d", &num);
printf(" Enter the Name : ");
scanf("%s", name);

/* Check availability */
if((availability(llist, name)) == 1){
printf(" Name %s is already exist\n", name);
break;
}
else{
printf(" Enter Opening Balance: Rs. ");
scanf("%f", &bal);
add_acc(llist, num, bal, name);
break;
}


case 2:
printf(" Delete Account\n");
printf(" ------------------------\n");
printf(" Enter Acc. No to Delete: ");
scanf("%d", &num);
del_acc(llist, num);
break;

case 3:
printf(" Diposit Amount\n");
printf(" ------------------------\n");
printf(" Enter the Account Number : ");
scanf("%d", &num);
printf(" Enter Amount : Rs. ");
scanf("%f", &amt);
diposit(llist, num, amt);
printf(" Printing Updated Balance : ");
display_list(llist, num);
break;


case 4:
printf(" Withdraw Amount\n");
printf(" ------------------------\n");
printf(" Enter the Account Number : ");
scanf("%d", &num);
printf(" Enter Amount : Rs. ");
scanf("%f", &amount);
withdraw(llist, num, amount);
printf(" Printing Updated Balance : ");
display_list(llist, num);
break;

case 5:
printf(" Search Account \n");
printf(" ------------------------\n");
printf(" Enter the Name: ");
scanf("%s", name);
if((find = search_value(llist, name)) == -1)
printf(" Account `%s' not found\n", name);
else
printf(" Account number :%d\n",find);
break;


case 6:
printf(" Display Account Data\n");
printf(" ------------------------\n");
printf(" Enter the Acc No : ");
scanf("%d", &num);
display_list(llist, num);
break;

case 9:
printf("\n Thank You for visit this Program\n");
printf(" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
choice = 0;
break;



default:
printf(" Invalid Code Entered \n");
break;
}
}

free(llist);
return(0);
}

/* Add Account */
void add_acc(struct NODE *llist, int num, float bal, char *acc_name) {
while(llist->next != NULL)
llist = llist->next;
llist->next = (struct NODE *)malloc(sizeof(struct NODE));
llist->next->name = malloc(64*sizeof(char));
llist->next->number = num;
llist->next->balance = bal;
strcpy(llist->next->name,acc_name);
//llist->next->name = acc_name;
llist->next->next = NULL;
}
/* Delete Account */
void del_acc(struct NODE *llist, int num) {
struct NODE *temp;
temp = (struct NODE *)malloc(sizeof(struct NODE));

if(llist->number == num) {
temp = llist->next;
free(llist);
llist = temp;
} else {
while(llist->next->number != num)
llist = llist->next;
temp = llist->next->next;
free(llist->next);
llist->next = temp;
}
}

/* Display Selected info */
void display_list(struct NODE *llist, int num) {
int i = 0;
while(llist->next != NULL) {
if(llist->next->number == num){

printf("\n Account Number :    %d \n", llist->next->number);
printf(" Account Owner :     %s \n", llist->next->name);
printf(" Account Balance :   Rs.  %.2f \n", llist->next->balance);
i++;
break;
}
llist = llist->next;
}
if(i==0)
printf(" Account is Not Available\n");
}

/* Diposit Amount */
void diposit(struct NODE *llist, int num, float amt){
int i = 0;
while(llist->next != NULL) {
if(llist->next->number == num){
float amt1=llist->next->balance;
llist->next->balance=amt1+amt;
printf(" Transaction Success !\n");
i++;
break;
}
llist = llist->next;
}
if(i==0)
printf(" Account is Not Available\n");
}

/* http://www.edulanka.lk */
/* Cash Withdrawal */
void withdraw(struct NODE *llist, int num, float amount){
int i = 0;
while(llist->next != NULL) {
if(llist->next->number == num){
float amt1=llist->next->balance;
if(amount<amt1){
llist->next->balance=amt1-amount;
printf(" Transaction Success !\n");
}
else{
printf(" Account Balance is not enough \n");
}
i++;
break;
}
llist = llist->next;
}
if(i==0)
printf(" Account is Not Available\n");
}

/* Availability Check*/
int availability(struct NODE *llist, char a_name[64]) {
while(llist->next != NULL) {
if(strcmp(llist->next->name, a_name)==0){
return 1;
}
else
llist = llist->next;
}
return -1;
}

/* Search by Name*/
int search_value(struct NODE *llist, char a_name[64]) {
while(llist->next != NULL) {
if(strcmp(llist->next->name, a_name)==0){
return llist->next->number;
}
else
llist = llist->next;

}
return -1;
}

/* Ending of the Program */
/* http://www.edulanka.lk */
Last Updated on Wednesday, 29 September 2010 15:09
 

Add comment

Add comments relevant to this Article. මෙම ලිපියට අදාලව පමණක් අදහස් එකතු කරන්න.


Security code
Refresh

5.jpg

Download Toolbar

 
 

Most Popular Articles

Latest Articles

Copyright © 2005 - 2016 (ඉස්කෝලේ) eduLanka Online Education School of Sri Lanka