ABA


"אני צריך עזרה דחוף בשפת C....."
גירסת הדפסה        
קבוצות דיון פיתוח, תיכנות ובניית אתרים נושא #5385 מנהל    סגן המנהל    מפקח   Winner    צל"ש   מומחה  
אשכול מספר 5385
liorlior1

   19:29   16.03.03   
אל הפורום  
  אני צריך עזרה דחוף בשפת C.....  
 
   יש לי פרוייקט שאני צריך לשלוח למורה שלי היום באי מייל ויש לי כמה באגים בתוכנית שאין לי מושג אין פותרים אותם....
התוכנית בעצם מדמה את התוכנה המצוייה בבנקים !

התוכנית משלבת רשימות מקושרות (יעני צריך לדעת טוב את הנושא הזה)

אם מישהו יגיד שהוא יכול לעזור לי אני אעלה לפה את התוכנית !

תודה......


                                שתף        
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד

  האשכול     מחבר     תאריך כתיבה     מספר  
  שים פה ת'קוד... Dudenland 16.03.03 19:54 1
     הנה: liorlior1 16.03.03 19:59 2
         יש לי שאלה שיהיה לכם יותר קל להבין.... liorlior1 16.03.03 20:02 3
         האם אתה עדיין צריך עזרה? orly 16.03.03 20:04 4
         שיראה נורמאלי: dryice 16.03.03 22:58 5
  אחי אם אתה עדיין צריך עזרה, תגיד, zoomzoom 18.03.03 00:42 6

       
Dudenland

   19:54   16.03.03   
אל הפורום  
  1. שים פה ת'קוד...  
בתגובה להודעה מספר 0
 
   נראה מה אפשר לתקן...

Dudenland


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד
liorlior1

   19:59   16.03.03   
אל הפורום  
  2. הנה:  
בתגובה להודעה מספר 1
 
   עבר עריכה לאחרונה בתאריך 16.03.03 בשעה 20:01
 
הנה:


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<alloc.h>

struct bank_account
{
char first_name;
char last_name;
char branch_name;
long ID;
long account_number;
long branch_number;
long caspomat_code;
int balance;
bank_account *next;
}*head;

void get_data();
void insert(struct bank_account *tmp);
void save_in_file();
void get_data_from_file();
void menu_update();
void update_data();
void change_balance();
void get_money_from_kaspomat();
void delete_account();
void balances_avg();
void menu_print();
void print_one_customer();
void print_some_details();
void print_table();

void main()
{
char act='a';
get_data_from_file();
printf("Helo!\n");
printf("\t\tWelcome to Lior Zeitouni's bank program !!!\n");
printf("\nWhat would you like to do ?\n");
while(act!='q')
{
clrscr();
printf("\n\t\tPress on \na - To add a new bank account ! \nu - To update some of your details ! \nd - To delete your bank account \np - To print your details \nq - To quit\n");
printf("\nIf you want special detail like balances avg press on 's'\n");
scanf("%c",&act);
switch(act)
{
case 'a':
{
get_data();
break;
}
case 'u':
{
menu_update();
break;
}
case 'd':
{
delete_account();
break;
}
case 'p':
{
menu_print();
break;
}
case 's':
{
balances_avg();
break;
}
case 'q': {
char exit;
clrscr();
printf("\n\nDo you want to save your data ? y/n");
scanf("%c",&exit);
if(exit == 'y')
save_in_file();
else
if(exit != 'n')


break;
}
}
}
}


void get_data()//the function get data gets data from the user
{
clrscr();
bank_account *tmp;
tmp=new bank_account;
if(tmp==NULL)
{
printf("NO MEMORY");
getch();
exit(1);
}
printf("\nEnter your privet name please\n");
scanf("%s",tmp->first_name);
printf("\nEnter your family name please\n");
scanf("%s",tmp->last_name);
printf("\nEnter ID please\n");
scanf("%ld",&tmp->ID);
printf("\nEnter account number please\n");
scanf("%ld",&tmp->account_number);
printf("\nEnter branch number please\n");
scanf("%ld",&tmp->branch_number);
printf("\nEnter the branch name please\n");
scanf("%s",&tmp->branch_name);
printf("\nEnter balance sum please\n");
scanf("%d",&tmp->balance);
printf("\nEnter caspomat number please\n");
scanf("%ld",&tmp->caspomat_code);
tmp->next=NULL;
insert(tmp);
printf("\n\nPress any key to get back to the Main Menu\n");
getch();
}


void insert(struct bank_account *tmp) //the function insert insert the datas to the right
{
bank_account *rectmp;
if(head==NULL)
{
head=tmp;
return;
}
if(head->account_number > tmp->account_number)
{
tmp->next=head;
head=tmp;
return;
}
rectmp=head;
while((rectmp->next!=NULL)&&(rectmp->next->account_number < tmp->account_number))
{
rectmp=rectmp->next;
}
tmp->next=rectmp->next;
rectmp->next=tmp;
return ;
}


void save_in_file()
{
struct bank_account *tmp;
tmp=head;
FILE *fp;
fp=fopen("lior_data.bin","wb");
if(fp==NULL)
{
printf("The file not exists");
getch();
exit(1);
}
while(tmp!=NULL)
{
fwrite(tmp,sizeof(bank_account),1,fp);
tmp=tmp->next;
}
fclose(fp);
printf("Saving completed !\n");
}


void get_data_from_file()
{
FILE *fp;
fp=fopen("lior_data.bin","rb");
if(fp==NULL)
{
printf("Can not open file");
getch();
exit(1);
}
while(!feof(fp))
{
bank_account *tmp;
tmp=new bank_account;
if(tmp==NULL)
{
printf("no memory");
getch();
exit(1);
}
fread(tmp,sizeof(bank_account),1,fp);
tmp->next=NULL;
insert(tmp);
}
}

void menu_update()
{
bank_account *rectmp=head;
long account_num;
char actU;
printf("\nEnter your account number please!\n");
scanf("%d",&account_num);
while((rectmp->next!=NULL)&&(rectmp->next->account_number<account_num))
{
rectmp=rectmp->next;
}
if(rectmp->next->account_number!=account_num)
{
printf("\nWrong account number !\n");
printf("\nPress any key to get back to the Main Menu\n");
getch();
}
else
{
printf("\nEnter a if you want to update your first and last name\n");
printf("\nEnter b if you want to change the balance sum of the bank account\n");
printf("\nEnter c if you want to take cash from your bank account\n");
scanf("%c",&actU);
switch(actU)
{
case 'a':
{
update_data();
break;
}
case 'b':
{
change_balance();
break;
}
case 'c':
{
get_money_from_kaspomat();
break;
}
}
}
}


void update_data()
{
clrscr();
if (head == NULL)
{
printf("\n\nAccount does'nt exist on the system.\n");
return;
}
else
{
bank_account *RecTemp;
RecTemp = head;
long account_num;
printf("\n\nEnter the desired Account Number = ");
scanf("%ld",&account_num);
printf("\n\n");
while (( RecTemp->next != NULL ) && ( RecTemp->account_number != account_num ))
{
RecTemp = RecTemp->next;
}
if ( RecTemp->account_number != account_num )
{
printf("\n\nAccount does'nt exist on the system.\n");
}
else
{
printf("Enter the new first name:\n\nFirst name = ");
scanf("%s",&RecTemp->first_name);
printf("Enter the new last name:\n\nLast name = ");
scanf("%s",&RecTemp->last_name);
printf("\n\nNew full name set to %s %s.",RecTemp->last_name,RecTemp->first_name);
getch();
clrscr();
}
}
}


void change_balance()//in this function the user insert the balance sum of bank_account
{
bank_account *rectmp;
rectmp=head;
long account_num;
printf("Enter your account number please !\n");
scanf("%ld",&account_num);
while((rectmp!=NULL)&&(rectmp->account_number!=account_num))
{
rectmp=rectmp->next;
}
if((rectmp->account_number==account_num))
{
printf("Enter the new balance please\n");
scanf("%ld",&rectmp->balance);
printf("The balance updated,you have now %ld NIS in your account\n",rectmp->balance);
}
else
{
printf("The requested account wasn't found\n");
}
printf("\nPress any key to get back to the Main Menu\n");
getch();
}

void get_money_from_kaspomat() //the function get_money_from_kaspomat gets the sum of money that the coustomer want to take out
{
bank_account *rectmp;
rectmp=head;
long withdrawal,card_num;
printf("Enter your card number please !\n");
scanf("%ld",&card_num);
while((rectmp!=NULL)&&(rectmp->caspomat_code!=card_num))
{
rectmp=rectmp->next;
}
if((rectmp->caspomat_code==card_num))
{
printf("Enter the sum of money that you want to take out from your bank account\n");
scanf("%d",&withdrawal);
rectmp->balance=rectmp->balance-withdrawal;
printf("You have %ld NIS left in your account\n",rectmp->balance);
}
else
{
printf("The requested account wasn't found\n");
}
printf("Press any key to get back to the Main Menu\n");
getch();

} //the function updating the sum balance after the coustomer take out sum of money

void menu_print() //the function menu print offers all the print possiblities
{
char actP;
printf("Enter a if you want to print all the coustomers detailes in table\n");
printf("Enter b if you want to print only one coustomer detailes\n");
printf("Enter c if you want to print only some detailes of one coustomer\n");
scanf("%c",&actP);
switch(actP)
{
case 'a':
{
print_table();
break;
}
case 'b':
{
print_one_customer();
break;
}
case 'c':
{
print_some_details();
break;
}
}
}//according to the answer of the user the function will go to the required function

void print_table()//the function print all the coustomers details in table
{
clrscr();
bank_account *rectmp;
rectmp=head;
printf("\t_\n");
printf("\t lFirst_namel Last_name l ID l\n");
printf("\t_\n");
while(rectmp->next!=NULL)
{
printf("\tl %sl%sl%ldl\n,rectmp->name,rectmp->last_name,rectmp->ID");
rectmp=rectmp->next;
}
printf("\t_\n");
}


void print_one_customer()//the function get the ID of coustomer
{
clrscr();
bank_account *rectmp;
int idprint;
rectmp=head;
printf("Enter the account number of the coustmer that you want to print his details\n");
scanf("%ld",&idprint);
while((rectmp!=NULL)&&(idprint!=rectmp->ID))
{
rectmp=rectmp->next;
}
if(rectmp->next==NULL)
{
printf("NULL");
getch();
}
else
{
printf("->",rectmp->first_name,rectmp->last_name,rectmp->ID);
printf("The account number of the customer is %ld",rectmp->account_number);
printf("The cspomat code of the customer is %ld",rectmp->caspomat_code);
printf("The branch name of the customer is %s",rectmp->branch_name);
printf("The branch number is %ld",rectmp->branch_number);
printf("The balance number of the customer is %d",rectmp->balance);
}
} //the function print all the coustomer details

void print_some_details() //the function gets the ID coustomer
{
clrscr();
struct bank_account *rectmp;
int idprint2;
rectmp=head;
printf("Enter the ID of the coustmer that you want to print some of his details\n");
scanf("%ld",&idprint2);
while((rectmp!=NULL)&&(idprint2!=rectmp->ID))
{
rectmp=rectmp->next;
}
if(rectmp->next==NULL)
{
printf("NULL");
getch();
}
else
{
printf("->",rectmp->first_name,rectmp->last_name);
printf("The account number of the customer is %ld",rectmp->account_number);
printf("The balance number of the customer is %d",rectmp->balance);
getch();
}
} //the function print some of his details


void delete_account()//The function asks the ID of the coustomer
{
bank_account *rectmp,*tmp;
rectmp=head;
long account_num;
printf("Enter the account number of the account that you would like to delete\n");
scanf("%ld",&account_num);
if(rectmp->account_number==account_num)
{
head=rectmp->next;
delete rectmp;
printf("The account was successfully deleted !\n");
return;
}
while((rectmp->next!=NULL)&&(rectmp->next->account_number!=account_num))
{
rectmp=rectmp->next;
}
if(rectmp->next->account_number==account_num)
{
tmp=rectmp->next;
rectmp->next=rectmp->next->next;
delete tmp;
printf("The account was successfully deleted !\n");
}
else
{
printf("The requested account wasn't found\n");
}
printf("Press any key to get back to the Main Menu\n");
getch();

} //The function delet the coustomer list


void balances_avg() //this function average gets the balance sums in the bank
{
bank_account *rectmp;
rectmp=head;

if (head == NULL)
{
printf("\n\nNo accounts on the system.\n");
printf("\nPress any key to get back to the Main Menu\n");
getch();
return;
}
float avg=0;
long sum=0;
int mone=0;
while (rectmp!= NULL)
{
avg=avg rectmp->balance;
mone ;
rectmp=rectmp->next;
}
avg=sum/mone;
printf("\nfor %d accounts, the average balance is %llf.\n\n",mone, avg);
printf("Press any key to get back to the Main Menu\n");
getch();
} //the function calculate the average of the balance sums in the bank and print it.


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד
liorlior1

   20:02   16.03.03   
אל הפורום  
  3. יש לי שאלה שיהיה לכם יותר קל להבין....  
בתגובה להודעה מספר 2
 
   איך עושים שזה יראה משמאל לימין ????


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד
orly

   20:04   16.03.03   
אל הפורום  
  4. האם אתה עדיין צריך עזרה?  
בתגובה להודעה מספר 2
 
   אם כן יהיה יותר נחמד אם במקום להריץ ולחפש באגים תגיד לי באי מייל איפה הבאגים העיקריים שאתה רואה ובאיזה קומפיילר השתמשת


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד
dryice

   22:58   16.03.03   
אל הפורום  
  5. שיראה נורמאלי:  
בתגובה להודעה מספר 2
 
   תכתוב בתחילת הקוד:
[code]

ובסופו:
[/code]

אבל קוד כזה, הוא טיפה ארוך והכי נוח זה אם אתה מעלה אותו כקובץ
טקסט נפרד.

(אני נוהג לעשות במקרים כאלו גם וגם)

DRYICE


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד
zoomzoom

   00:42   18.03.03   
אל הפורום  
  6. אחי אם אתה עדיין צריך עזרה, תגיד,  
בתגובה להודעה מספר 0
 
   עבר עריכה לאחרונה בתאריך 18.03.03 בשעה 00:43
 
רק תסדר את הקוד שיהיה ברור...


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד

תגובה מהירה  למכתב מספר: 
 
___________________________________________________________________

___________________________________________________________________
למנהלים:  נעל | תייק בארכיון | מחק | העבר לפורום אחר | מחק תגובות | עגן אשכול
       



© כל הזכויות שמורות ל-רוטר.נט בע"מ rotter.net