Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <stdlib.h>
- #include <conio.h>
- extern "C" float SREDNIA(float tab[], short ile);
- extern "C" short ZNAKI(char tab[], char _char);
- //extern - Funkcja, która wywoływana będzie z modułu powstałego w języku np C, a znajduje się poza
- //tym modułem, musi zostać zadeklarowana jako zewnętrzna.
- //W języku C obowiązuje jednak w odniesieniu do funkcji specyficzna konwencja
- //nazewnicza (ang. naming convention), zgodnie z którą w trakcie kompilacji nazwy
- //wszystkich funkcji ulegają modyfikacji: na ich początku dodany zostaje _char podkreślenia.
- //Ponieważ odwołania do procedur umieszczonych w różnych modułach podlegają
- //dopasowaniu dopiero na etapie konsolidacji programu, oznacza to, że nazwy procedur
- //asemblerowych odpowiadających zewnętrznym funkcjom modułu utworzonego w
- //języku C muszą również zawierać ów _char podkreślenia.
- int main()
- {
- char _char, choice;
- char array[21];
- short N;
- do
- {
- system("cls");
- cout<<"Wybierz wariant\n"
- <<"1. Average of all elements in an array\n"
- <<"2. Number of occurences of a char in a string\n"
- <<"3. Exit";
- if(bad_keystroke) cout<<"\nWrong option";
- choice=getch();
- switch(choice)
- {
- case '1':
- {
- system("cls");
- cout<<"Average of all elements in a float array t\n";
- cout<<"\nDefine array size: ";
- cin>>N;
- while(cin.fail() || N<=0 || N>32766)
- {
- cout<<"Invalid size. Try again";
- cin.clear();
- cin.sync();
- cin>>N;
- }
- float *tab2=new float [N];
- cout<<"\nInsert the next aray value and press Enter to confirm\n";
- for(int i=0; i<N; i++)
- {
- cin>>tab2[i];
- while(cin.fail() || tab2[i]<-3.4E38 || tab2[i]>3.4E38)
- {
- cout<<"Invalid number.Try again.\n";
- cin.clear();
- cin.sync();
- cin>>tab2[i];
- }
- }
- cout<<"\n Assembler procedure call";
- cout<<"\naverage: "<<SREDNIA(tab2, N) << endl;
- system("pause");
- delete [] tab2;
- tab2=0;
- bad_keystroke=0;
- break;
- }
- case '2':
- {
- system("cls");
- cout<<"Number of occurences of a char in a string";
- cout<<"\nType in a word. Limit: 20chars \n";
- cin.sync();
- cin.getline(array, 21);
- cout<<"Select the char for occurence: ";
- cin.sync();
- _char=getch();
- cout<<"\nSelected char: "<<_char;
- cout<<"\nAssembler procedure call";
- cout<<"\nAmount of occurences: "<<ZNAKI(array, _char) << endl;
- system("pause");
- bad_keystroke=0;
- break;
- }
- case '3': break;
- default: bad_keystroke=1;
- }
- }
- while(choice!='3');
- return 0;
- }
Add Comment
Please, Sign In to add comment