Mateusz8868

Untitled

Apr 26th, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5. extern "C" float SREDNIA(float tab[], short ile);
  6. extern "C" short ZNAKI(char tab[], char _char);
  7. //extern - Funkcja, która wywoływana będzie z modułu powstałego w języku np C, a znajduje się poza
  8. //tym modułem, musi zostać zadeklarowana jako zewnętrzna.
  9.  
  10. //W języku C obowiązuje jednak w odniesieniu do funkcji specyficzna konwencja
  11. //nazewnicza (ang. naming convention), zgodnie z którą w trakcie kompilacji nazwy
  12. //wszystkich funkcji ulegają modyfikacji: na ich początku dodany zostaje _char podkreślenia.
  13. //Ponieważ odwołania do procedur umieszczonych w różnych modułach podlegają
  14. //dopasowaniu dopiero na etapie konsolidacji programu, oznacza to, że nazwy procedur
  15. //asemblerowych odpowiadających zewnętrznym funkcjom modułu utworzonego w
  16. //języku C muszą również zawierać ów _char podkreślenia.
  17. int main()
  18. {
  19. char _char, choice;
  20. char array[21];
  21. short N;
  22.  
  23. do
  24. {
  25. system("cls");
  26. cout<<"Wybierz wariant\n"
  27. <<"1. Average of all elements in an array\n"
  28. <<"2. Number of occurences of a char in a string\n"
  29. <<"3. Exit";
  30. if(bad_keystroke) cout<<"\nWrong option";
  31. choice=getch();
  32. switch(choice)
  33. {
  34. case '1':
  35. {
  36. system("cls");
  37. cout<<"Average of all elements in a float array t\n";
  38. cout<<"\nDefine array size: ";
  39. cin>>N;
  40. while(cin.fail() || N<=0 || N>32766)
  41. {
  42. cout<<"Invalid size. Try again";
  43. cin.clear();
  44. cin.sync();
  45. cin>>N;
  46. }
  47. float *tab2=new float [N];
  48. cout<<"\nInsert the next aray value and press Enter to confirm\n";
  49. for(int i=0; i<N; i++)
  50. {
  51. cin>>tab2[i];
  52. while(cin.fail() || tab2[i]<-3.4E38 || tab2[i]>3.4E38)
  53. {
  54. cout<<"Invalid number.Try again.\n";
  55. cin.clear();
  56. cin.sync();
  57. cin>>tab2[i];
  58. }
  59. }
  60. cout<<"\n Assembler procedure call";
  61. cout<<"\naverage: "<<SREDNIA(tab2, N) << endl;
  62. system("pause");
  63. delete [] tab2;
  64. tab2=0;
  65. bad_keystroke=0;
  66. break;
  67. }
  68. case '2':
  69. {
  70. system("cls");
  71. cout<<"Number of occurences of a char in a string";
  72. cout<<"\nType in a word. Limit: 20chars \n";
  73. cin.sync();
  74. cin.getline(array, 21);
  75. cout<<"Select the char for occurence: ";
  76. cin.sync();
  77. _char=getch();
  78. cout<<"\nSelected char: "<<_char;
  79. cout<<"\nAssembler procedure call";
  80. cout<<"\nAmount of occurences: "<<ZNAKI(array, _char) << endl;
  81. system("pause");
  82. bad_keystroke=0;
  83. break;
  84. }
  85. case '3': break;
  86. default: bad_keystroke=1;
  87. }
  88. }
  89. while(choice!='3');
  90. return 0;
  91. }
Add Comment
Please, Sign In to add comment