Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include "math.h"
- #include <cstdlib>
- #include <cstdio>
- using namespace std;
- class Number {
- private:
- char sign;
- char* arr;
- int schetnamber (int i)
- {
- return i > 0 ? (int) log10 ((double) i) + 1 : 1;
- }
- int podschet_par(int kolchisel) {
- if (kolchisel % 2 == 0) {
- return kolchisel / 2;
- }
- else {
- return kolchisel / 2 + 1;
- }
- }
- void Chifry_arr(int kolvo_par,int number, char *arr) {
- int i = 0;
- while (number!=0) {
- int x = number % 100;
- arr[i]=(char)x;
- number = number/100;
- cout << "vassiv - ";
- printf("%d", arr[i]);
- cout << "\n";
- i++;
- }
- };
- public:
- Number(char sign, int number) {
- int kolchisel = schetnamber(number);
- cout << "kolichstvo chisel - " << kolchisel << "\n";
- int kolvo_par = podschet_par(kolchisel);
- cout << "kolvo_par - " << kolvo_par << "\n";
- //double *price = new double[rows];
- //arr = new char[kolvo_par];
- arr = (char* )malloc(kolchisel * sizeof(char));
- Chifry_arr(kolvo_par, number, arr);
- this->sign = sign;
- //this->arr[0] = number;
- }
- void printConsole() {
- cout << "size of char - " << sizeof(char) << "\n";
- cout << "size of array in bytes - " << sizeof(arr) << "\n";
- cout << "size of one element of array - " << sizeof(arr[0]) << "\n";
- cout << "size of array - " << sizeof(arr)/sizeof(arr[0]) << "\n";
- cout << "!!!!!!!!";
- char a[6] = {1,2,3,4,5,6};
- cout << "size of array in bytes - " << sizeof(a) << "\n";
- cout << "size of one element of array - " << sizeof(a[0]) << "\n";
- cout << "size of array - " << sizeof(a)/sizeof(a[0]) << "\n";
- cout << "!!!!!!!!" << "\n";
- cout << sign;
- for (int j = 3; j >=0; j--) {
- printf("%d", arr[j]);
- }
- }
- };
- int main(){
- // int i;
- // cout << "vvedite chislo" << endl;
- // cin >> i;
- // Number number1('+', i);
- Number number1('+', 123456);
- number1.printConsole();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement