Advertisement
SAADQUAMER

Project

Aug 17th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.39 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct currency
  5. {
  6.     char S1[100];
  7.     float rate;
  8.     int dat;
  9. };
  10.  
  11.  
  12. //edit
  13. void edit()
  14. {
  15.     system("CLS");
  16.     FILE *old,*newrec;
  17.     old=fopen("record.txt","a+");
  18.     newrec=fopen("record.txt","a+");
  19.  
  20.     int test1=0,choice;
  21.  
  22.     char s1[100],s2[100];
  23.     struct currency rt;
  24.     printf("\n\t<<<<<<<<Welcome To Currency Convertion>>>>>>>>");
  25.     printf("\n\n\tEnter Edit Country Name :");
  26.     scanf("%s",&s1);
  27.     {
  28.  
  29.         while(fscanf(old,"%s %f",&rt.S1,&rt.rate)!=EOF)
  30.         {
  31.             if(strcmp(rt.S1,s1)==0)
  32.             {
  33.                 test1++;
  34.                 printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  35.  
  36.                 printf("\n\nEnter Country New Rate:");
  37.                 scanf("%f",&rt.rate);
  38.                 printf("\t\t Country :%s   rate= %.2f\n\n",rt.S1,rt.rate);
  39.  
  40.                 fprintf(newrec,"\t%s\t\t%.2f\n",rt.S1,rt.rate);
  41.                 printf("Changes saved!");
  42.             }
  43.         }
  44.         }
  45.         fclose(old);
  46.         fclose(newrec);
  47.  
  48.           if(test1==0)
  49.             printf("\n\tRecord not found!!");
  50.  
  51.     printf("\n\nEnter 1 to go to the Admin panel and 2 to Edit Again:");
  52.     scanf("%d",&choice);
  53.  
  54.     if (choice==1)
  55.             admin();
  56.     else if(choice==2)
  57.         edit();
  58.  
  59.  
  60. }//edit
  61.  
  62.  
  63.  
  64. //conversion
  65.  
  66. void convertion()
  67. {
  68.     system("CLS");
  69.     FILE *view;
  70.     int test1=0,test2=0,choice;
  71.     view=fopen("record.txt","r");
  72.     char s1[100],s2[100];
  73.     struct currency rt;
  74.     printf("\n\t<<<<<<<<Welcome To Currency Convertion>>>>>>>>");
  75.     printf("\n\n\tEnter Your First Country Name :");
  76.     scanf("%s",&s1);
  77.     {
  78.  
  79.         while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
  80.         {
  81.             if(strcmp(rt.S1,s1)==0)
  82.             {
  83.                 test1++;
  84.                 printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  85.             }
  86.         }
  87.         fclose(view);
  88.         if(test1==0)
  89.             printf("\n\tRecord not found!!");
  90.     }
  91.  
  92.     printf("\n\n\tEnter Your Second Country Name :");
  93.     scanf("%s",&s2);
  94.     {
  95.  
  96.         while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
  97.         {
  98.             if(strcmp(rt.S1,s2)==0)
  99.             {
  100.                 test1++;
  101.                 printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  102.             }
  103.         }
  104.         fclose(view);
  105.         if(test1==0)
  106.             printf("\n\tRecord not found!!");
  107.     }
  108.  
  109.  
  110.  
  111.  
  112.  
  113. }
  114. //conversion
  115.  
  116.  
  117. void search()
  118. {
  119.     system("CLS");
  120.     FILE *view;
  121.     int test=0,choice;
  122.     view=fopen("record.txt","r");
  123.     char s2[100];
  124.     struct currency rt;
  125.     printf("\n\t<<<<<<<<Welcome To Search Option>>>>>>>>");
  126.     printf("\n\n\tEnter Your Country Name :");
  127.     scanf("%s",&s2);
  128.  
  129.     while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
  130.     {
  131.         if(strcmp(rt.S1,s2)==0)
  132.         {
  133.             test++;
  134.             printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  135.         }
  136.     }
  137.     fclose(view);
  138.     if(test==0)
  139.         printf("\n\tRecord not found!!");
  140.     printf("\n\nEnter 1 to go to the main menu and 2 to Search Again:");
  141.     scanf("%d",&choice);
  142.  
  143.     if (choice==1)
  144.         Menu();
  145.     else if(choice==2)
  146.         search();
  147.     else
  148.     {
  149.         printf("\nInvalid!\a");
  150.  
  151.     }
  152.  
  153.  
  154.  
  155.  
  156. }
  157.  
  158.  
  159. void details()
  160. {
  161.  
  162.     system("CLS");
  163.     FILE *view;
  164.     view=fopen("record.txt","r");
  165.     int test=0,choice;
  166.     struct currency rt;
  167.     printf("\n\tCountry\t\t\tRate\t\t\t\n");
  168.  
  169.     while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
  170.     {
  171.         printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  172.         test++;
  173.     }
  174.     fclose(view);
  175.  
  176.     if (test==0)
  177.     {
  178.         printf("\nNO RECORDS!!\n");
  179.     }
  180.  
  181. view_list_invalid:
  182.     printf("\n\nEnter 1 to go to the main menu and 2 to exit:");
  183.     scanf("%d",&choice);
  184.  
  185.     if (choice==1)
  186.         Menu();
  187.     else if(choice==2)
  188.         admin();
  189.     else
  190.     {
  191.         printf("\nInvalid!\a");
  192.  
  193.     }
  194. }
  195.  
  196. void add()
  197. {
  198.     system("CLS");
  199.     FILE *currency;
  200.  
  201.     int add,i,choice;
  202.  
  203.     currency = fopen("record.txt","a+");
  204.     printf("\n\t\t\t<<<<<<<<< ADD CURRENCY DATA >>>>>>>>>\n\n");
  205.  
  206.     printf("Enter How Many Country You Want To Add :");
  207.     scanf("%d",&add);
  208.     struct currency rt;
  209.     for(i=1; i<=add; i++)
  210.     {
  211.         printf("%d.Enter Your Country :",i);
  212.         scanf("%s",&rt.S1);
  213.         printf("%d Enter Your Country Rate:",i);
  214.         scanf("%f",&rt.rate);
  215.         printf("\t%d. Country :%s   rate= %.2f\n\n",i,rt.S1,rt.rate);
  216.  
  217.         fprintf(currency,"%s\t\t%.2f\n",rt.S1,rt.rate);
  218.     }
  219.     printf("\nFile is written successfully");
  220.     fclose(currency);
  221.     printf("\n\t\t\t<<<<<< Country added successfully!>>>>>>>");
  222.     printf("\n\n\t\t Enter 1 to go to the Admin Panel and 2 to exit:");
  223.     scanf("%d",&choice);
  224.     switch(choice)
  225.     {
  226.     case 1:
  227.         admin();
  228.         break;
  229.     case 2:
  230.         Menu();
  231.         break;
  232.     }
  233.  
  234. }
  235.  
  236.  
  237. void admin()
  238. {
  239.     system("CLS");
  240.     int choice;
  241.     printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n");
  242.     printf("\n\t  <<<<<<<<Welcome To Admin Panel>>>>>>>>>>>>\n\n");
  243.     printf("\t  1) Add Country Information\n");
  244.     printf("\t  2) Edit Country Information\n");
  245.     printf("\t  3) Show Currency Details\n");
  246.     printf("\t  4) Search Country\n");
  247.     printf("\t  5) Exit\n");
  248.  
  249.  
  250.     printf("\n\t Enter Your Choice (1-6):");
  251.     scanf("%d",&choice);
  252.     switch(choice)
  253.     {
  254.     case 1:
  255.         add();
  256.         break;
  257.     case 2:
  258.         edit();
  259.         break;
  260.     case 3:
  261.         details();
  262.         break;
  263.     case 4:
  264.         search();
  265.         break;
  266.     case 5:
  267.         Menu();
  268.         break;
  269.     default:
  270.         printf("Invalid Input!!! Input Again...\n");
  271.  
  272.         admin();
  273.  
  274.     }
  275.  
  276.  
  277. }
  278. void user()
  279. {
  280.     system("CLS");
  281.     int choice;
  282.     printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n");
  283.     printf("\n\t  <<<<<<<<Welcome To User Panel>>>>>>>>>>>>\n\n\n");
  284.     printf("\t  1) Search Country\n");
  285.     printf("\t  2) Currency Convertion\n");
  286.     printf("\t  3) Show Currency Details\n");
  287.     printf("\t  4) Exit\n");
  288.  
  289.  
  290.  
  291.     printf("\n\t Enter Your Choice (1-4):");
  292.     scanf("%d",&choice);
  293.     switch(choice)
  294.     {
  295.     case 1:
  296.         search();
  297.         break;
  298.     case 2:
  299.         convertion();
  300.         break;
  301.     case 3:
  302.         details();
  303.         break;
  304.     case 4:
  305.         Menu();
  306.         break;
  307.  
  308.     default:
  309.         printf("Invalid Input!!! Input Again...\n");
  310.  
  311.         user();
  312.  
  313.     }
  314.  
  315.  
  316. }
  317. int main()
  318. {
  319.     Menu();
  320.     return 0;
  321. }
  322. void Menu()
  323. {
  324.     system("CLS");
  325.     int choice;
  326.  
  327.     printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n\n");
  328.  
  329.     printf("\t  <<<<<<<<Welcome To Main Menu>>>>>>>>>>>\n\n");
  330.     printf("\t  1) Admin Login\n");
  331.     printf("\t  2) User \n");
  332.     printf("\n\t Enter Your Choice (1 or 2):");
  333.     scanf("%d",&choice);
  334.     switch(choice)
  335.     {
  336.     case 1:
  337.         pass();
  338.         admin();
  339.         break;
  340.     case 2:
  341.         user();
  342.         break;
  343.     default:
  344.         printf("Invalid Input!!! Input Again...\n");
  345.         Menu();
  346.  
  347.     }
  348.     return 0;
  349. }
  350. int pass(void)
  351. {
  352.     int a=0,i=0;
  353.     char uname[10],c=' ';
  354.     char pword[10],code[10];
  355.     char user[10]="saad";
  356.     char pass[10]="207661";
  357.     do
  358.     {
  359.         system("cls");
  360.  
  361.         printf("\n  ************************** ADMIN LOGIN FORM  **************************  ");
  362.         printf("\n\n                       ENTER USERNAME:-");
  363.         scanf("%s", &uname);
  364.         printf("\n\n                       ENTER PASSWORD:-");
  365.         while(i<10)
  366.         {
  367.             pword[i]=getch();
  368.             c=pword[i];
  369.             if(c==13)
  370.                 break;
  371.             else
  372.                 printf("*");
  373.             i++;
  374.         }
  375.         pword[i]='\0';
  376.  
  377.         i=0;
  378.  
  379.         if(strcmp(uname,user)==0 && strcmp(pword,pass)==0)
  380.         {
  381.             printf("  \n\n\n     <<<<<<<<< WELCOME !!!! LOGIN IS SUCCESSFUL >>>>>>>>>\n\n\n");
  382.             system("PAUSE");
  383.             break;
  384.         }
  385.         else
  386.         {
  387.             printf("\n        <<<<<<<<<SORRY !!!!  LOGIN IS UNSUCESSFUL>>>>>>>>> \n\n");
  388.             a++;
  389.             if (a==3)
  390.             {
  391.                 printf("\nSorry you have entered the wrong username or password for three times!!!");
  392.  
  393.                 Menu();
  394.  
  395.             }
  396.  
  397.             system("PAUSE");
  398.  
  399.  
  400.  
  401.         }
  402.     }
  403.     while(a<=2);
  404.  
  405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement