Advertisement
ivantuting

basics of c

Feb 12th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <string>
  6. #include <sstream>
  7. using namespace std;
  8.  
  9. main()
  10. {  
  11.  //-------------------------------------------LOG-IN PROCESS-----------------------------------------------------------    
  12.     int attempt = 1, menu;
  13.     char req_pass[256] = {0};
  14.     char buffer_reset[256] = {0};
  15.     char password[] = "welcome1";
  16.     char c;//save slot for the key that the user entered
  17.     char buffer[256] = {0};
  18.     char pass_old[256] = {0};
  19.     char pass_new[256] = {0};
  20.     char pass_new2[256] = {0};
  21.     int pos = 0;//counter
  22.      
  23.       do
  24.       {
  25.       pos = 0;
  26.       cout << "Username : Admin\nPassword : ";
  27.       do
  28.                 {
  29.                     c = getch();
  30.        
  31.                     if( isprint(c) )
  32.                     {
  33.                        buffer[ pos++ ] = c;
  34.                        printf("%c", '*');
  35.                        
  36.                     }
  37.                 } while( c != 13 );
  38.                 cout << buffer;
  39.  
  40.                
  41.       if( !strcmp(buffer, password))
  42.                   {
  43.                   cout << "Login successful!!!...";
  44.                   system("cls");
  45.                   attempt = 4;
  46.                   menu = 1;
  47.                   }
  48.       else
  49.           {
  50.           if(attempt < 3)
  51.                      {
  52.                      cout << "\n\nInvalid username/password. Press any key to continue\n\n[password entered : " << buffer << "]";
  53.                      getch();
  54.                      int counter = 0;
  55.                      do{
  56.                              
  57.                              }while(c != 13);
  58.                      system("cls");
  59.                      }
  60.           else
  61.           cout << "\n\nInvalid username/password. Contact Technical Support Team at Extension 143.\n Thank you.";
  62.           }
  63.       attempt++;
  64.       }while(attempt <= 3);
  65.      
  66.       //Main Menu
  67.       MAIN:
  68.       if(menu == 1){
  69.         int menu_choice;
  70.         cout << "[Basics of C]\n";
  71.         cout << "(1)Variables\n(2)Constants\n(3)Operators\n(4)Basic Input and Output\n(5)Control Structure\n(6)Arrays\n(7)Exit\n\nWhat do you want to do? : ";
  72.         cin >> menu_choice;
  73.         system("cls");
  74.             switch(menu_choice){
  75.                 case 1:{
  76.                    
  77.                     cout << "Variables";
  78.                     cout << "\n- Are used in c++ , where we need storage for any value, which will change in program.\nIt can be declared in multiple ways each different memory requirements and functioning.\nVariable is the name of memory location allocated by the compiler depending upon the data type of the variable.\n\n\n";
  79.                    
  80.                    
  81.                     int sample1 = 0;
  82.                         int n;
  83.                       do{
  84.                        
  85.                             do {
  86.                                     cout << "[Sample Program]";
  87.                                     cout << "Enter a number (0 to end):";
  88.                                     cin >> n;
  89.                                     cout << "You entered:" << n<< "\n";
  90.                                 } while (n!=0);
  91.                             char retry;
  92.                             int again =0;
  93.                             do{
  94.                            
  95.                                 cout << "\n Do you want to try the program again? <Y/N>:";
  96.                                 cin >> retry;
  97.                                 switch(retry)
  98.                                 {
  99.                                     case 'y':
  100.                                     case 'Y':
  101.                                         again = 1;
  102.                                         system("cls");
  103.                                         break;
  104.                                     case 'n':
  105.                                     case 'N':
  106.                                         sample1++;
  107.                                         again = 1;
  108.                                         system("cls");
  109.                                         cout << "\n ...Returning to main menu.";
  110.                                         system("cls");
  111.                                         getch();
  112.                                         goto MAIN;
  113.                                         break;
  114.                                     default:
  115.                                         cout << "Invalid input press any key...";
  116.                                         getch();
  117.                                 }
  118.                             }while(again != 1);
  119.                            
  120.                     }while(sample1 < 1);
  121.                     break;
  122.                 }
  123.                 case 2:{
  124.                    
  125.                     cout << "Constants";
  126.                     cout << "- Can be any of the basic data types and can be divided into Integer Numerals,\n Floating-Point Numerals, Characters, Strings, and Boolean Values.\n\n\n";
  127.                    
  128.                    
  129.                     int sample2 = 0;
  130.                    
  131.                       do{
  132.                         {
  133.                        
  134.                             string mystr;
  135.                             float price=0;
  136.                             int quantity=0;
  137.                             cout << "[Sample Program]";
  138.                             cout << "\nEnter price:";
  139.                             cin >> price;
  140.                            
  141.                             cout << "\nEnter quantity:";
  142.                             cin >> quantity;
  143.                            
  144.                             cout << "\nTotal price:" << price*quantity;
  145.                         }
  146.                             char retry2;
  147.                             int again2 =0;
  148.                             do{
  149.                            
  150.                                 cout << "\n Do you want to try the program again? <Y/N>:";
  151.                                 cin >> retry2;
  152.                                 switch(retry2)
  153.                                 {
  154.                                     case 'y':
  155.                                     case 'Y':
  156.                                         again2 = 1;
  157.                                         system("cls");
  158.                                         break;
  159.                                     case 'n':
  160.                                     case 'N':
  161.                                         sample2++;
  162.                                         again2 = 1;\
  163.                                         system("cls");
  164.                                         cout << "\n ...Returning to main menu.";
  165.                                         system("cls");
  166.                                         getch();
  167.                                         goto MAIN;
  168.                                         break;
  169.                                     default:
  170.                                         cout << "Invalid input press any key...";
  171.                                         getch();
  172.                                 }
  173.                             }while(again2 != 1);
  174.                            
  175.                     }while(sample2 < 1);
  176.                     break;
  177.             }
  178.                 case 3:{
  179.                     cout << "Operators";
  180.                     cout << "It is a symbol that tells the compiler to perform specific mathematical or logical manipulations.\n C++ is rich in built-in operators and provides the following typed of operators:\n Arithmetic Operators and Relational Operators.\n\n";
  181.                    
  182.                    
  183.                     int sample3 = 0;
  184.                         int n;
  185.                       do{
  186.                        
  187.                        
  188.                         cout << "Enter an Arithmetic Operator: ";
  189.                         char a;
  190.                         float d,e;
  191.                         int b,c;
  192.                         cin >> a;
  193.                         char repeat;
  194.                         switch (a)
  195.                         {
  196.                         case '+':
  197.                              cout << "Enter your first number: \n";
  198.                              cin >> b;
  199.                              cout << "Enter your second number: \n";
  200.                              cin >> c;
  201.                              cout << "The result is: ";
  202.                              cout << b+c;
  203.                              cout << endl;
  204.                              break;
  205.                         case '-':
  206.                              cout << "Enter your first number: \n";
  207.                              cin >> b;
  208.                              cout << "Enter your second number: \n";
  209.                              cin >> c;
  210.                              cout << "The result is: " << endl;
  211.                              cout << b-c;
  212.                              cout << endl;
  213.                              break;
  214.                         case '*':
  215.                              cout << "Enter your first number: \n";
  216.                              cin >> b;
  217.                              cout << "Enter your second number: \n";
  218.                              cin >> c;
  219.                              cout << "The result is: ";
  220.                              cout << b*c;
  221.                              cout << endl;
  222.                              break;
  223.                         case '/':
  224.                              cout << "Enter your first number: \n";
  225.                              cin >> d;
  226.                              cout << "Enter your second number: \n";
  227.                              cin >> e;
  228.                              cout << "The result is: ";
  229.                              cout << d/e;
  230.                              cout << endl;
  231.                              break;
  232.                         case '%':
  233.                              cout << "Enter your first number:\n";
  234.                              cin >> b;
  235.                              cout << "Enter your second number:\n";
  236.                              cin >> c;
  237.                              cout << "The result is: ";
  238.                              cout << b%c;
  239.                              cout << endl;
  240.                              break;
  241.                         default:
  242.                                 cout << "Invalid key!\n";
  243.                                 cout<<"Please choose only <*,/,+,-,%>\n" << endl;
  244.                                 }
  245.                             char retry3;
  246.                             int again3 =0;
  247.                             do{
  248.                            
  249.                                 cout << "\n Do you want to try the program again3? <Y/N>:";
  250.                                 cin >> retry3;
  251.                                 switch(retry3)
  252.                                 {
  253.                                     case 'y':
  254.                                     case 'Y':
  255.                                         again3 = 1;
  256.                                         system("cls");
  257.                                         break;
  258.                                     case 'n':
  259.                                     case 'N':
  260.                                         sample3++;
  261.                                         again3 = 1;
  262.                                         system("cls");
  263.                                         cout << "\n ...Returning to main menu.";
  264.                                         system("cls");
  265.                                         getch();
  266.                                         goto MAIN;
  267.                                         break;
  268.                                     default:
  269.                                         cout << "Invalid input press any key...";
  270.                                         getch();
  271.                                 }
  272.                             }while(again3 != 1);
  273.                            
  274.                     }while(sample3 < 1);
  275.                     break;
  276.                 }
  277.                 case 4:{
  278.                     cout << "Basic Input and Output\n";
  279.                     cout << "";
  280.                    
  281.                    
  282.                     int sample4 = 0;
  283.                         int n;
  284.                       do{
  285.                        
  286.                         //Copy paste mo dito ung sample program.
  287.                        
  288.                         //=========================================
  289.                        
  290.                             char retry4;
  291.                             int again4 =0;
  292.                             do{
  293.                            
  294.                                 cout << "\n Do you want to try the program again4? <Y/N>:";
  295.                                 cin >> retry4;
  296.                                 switch(retry4)
  297.                                 {
  298.                                     case 'y':
  299.                                     case 'Y':
  300.                                         again4 = 1;
  301.                                         system("cls");
  302.                                         break;
  303.                                     case 'n':
  304.                                     case 'N':
  305.                                         sample4++;
  306.                                         again4 = 1;
  307.                                         system("cls");
  308.                                         cout << "\n ...Returning to main menu.";
  309.                                         system("cls");
  310.                                         getch();
  311.                                         goto MAIN;
  312.                                         break;
  313.                                     default:
  314.                                         cout << "Invalid input press any key...";
  315.                                         getch();
  316.                                 }
  317.                             }while(again4 != 1);
  318.                            
  319.                     }while(sample4 < 1);
  320.                     break;
  321.                 }
  322.                 case 5:{
  323.                     cout << "Control Structure\n";
  324.                     cout << "It is the basic entities of a structured programming language. Control structure  is used to alter the flow of execution of the program.";
  325.                    
  326.                    
  327.                     int sample5 = 0;
  328.                         int n;
  329.                       do{
  330.                        
  331.                         //Copy paste mo dito ung sample program.
  332.                        
  333.                         //=========================================
  334.                        
  335.                             char retry5;
  336.                             int again5 =0;
  337.                             do{
  338.                            
  339.                                 cout << "\n Do you want to try the program again5? <Y/N>:";
  340.                                 cin >> retry5;
  341.                                 switch(retry5)
  342.                                 {
  343.                                     case 'y':
  344.                                     case 'Y':
  345.                                         again5 = 1;
  346.                                         system("cls");
  347.                                         break;
  348.                                     case 'n':
  349.                                     case 'N':
  350.                                         sample5++;
  351.                                         again5 = 1;
  352.                                         system("cls");
  353.                                         cout << "\n ...Returning to main menu.";
  354.                                         system("cls");
  355.                                         getch();
  356.                                         goto MAIN;
  357.                                         break;
  358.                                     default:
  359.                                         cout << "Invalid input press any key...";
  360.                                         getch();
  361.                                 }
  362.                             }while(again5 != 1);
  363.                            
  364.                     }while(sample5 < 1);
  365.                     break;
  366.                 }
  367.                 case 6:{
  368.                     cout << "Arrays\n";
  369.                     cout << "Stores a fixed-size type. An array is used to store a collection of data, but it is more useful to think of an array collection of variables of the same type.";
  370.                    
  371.                    
  372.                     int sample6 = 0;
  373.                         int n;
  374.                       do{
  375.                        
  376.                         //Copy paste mo dito ung sample program.
  377.                        
  378.                         //=========================================
  379.                        
  380.                             char retry6;
  381.                             int again6 =0;
  382.                             do{
  383.                            
  384.                                 cout << "\n Do you want to try the program again6? <Y/N>:";
  385.                                 cin >> retry6;
  386.                                 switch(retry6)
  387.                                 {
  388.                                     case 'y':
  389.                                     case 'Y':
  390.                                         again6 = 1;
  391.                                         system("cls");
  392.                                         break;
  393.                                     case 'n':
  394.                                     case 'N':
  395.                                         sample6++;
  396.                                         again6 = 1;
  397.                                         system("cls");
  398.                                         cout << "\n ...Returning to main menu.";
  399.                                         system("cls");
  400.                                         getch();
  401.                                         goto MAIN;
  402.                                         break;
  403.                                     default:
  404.                                         cout << "Invalid input press any key...";
  405.                                         getch();
  406.                                 }
  407.                             }while(again6 != 1);
  408.                            
  409.                     }while(sample6 < 1);
  410.                     break;
  411.                 }
  412.                
  413.                 case 7:{
  414.                     system("cls");
  415.                    cout << "Thank you for using the inventory program...\n\nPress any key to exit...";
  416.                     break;
  417.                 }
  418.                
  419.                
  420.                
  421.             }
  422.       }
  423.       //====================================
  424.      
  425.       getch();
  426.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement