SAADQUAMER

Final Project

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