C/C++

  • Креатор на темата Креатор на темата Драган
  • Време на започнување Време на започнување
Шо ти треба? С или С++?

Каква е таа класа? Ако е класа претпоставувам дека е С++.

Како да ги демонстрираме? Да ги преоптовариме да не сакаш?
 
Шо ти треба? С или С++?

Каква е таа класа? Ако е класа претпоставувам дека е С++.

Како да ги демонстрираме? Да ги преоптовариме да не сакаш?

C++ e напишав е па малку комплицирано е :) затоа ми треба.
Инаку ова Biginteger е карактеристично за JAVA ама мене ми го дадоа за C++ да го направам нешто.

Define a class Biginteger that stores arbitrary large integers, by keeping their digits in a dynamically allocated array of integers.
Supply the "big three" memory management functions.
И потоа треба да се демонстрира
(a) the difference between initialization
Biginteger s;
Biginteger t = s;
and assignment
Biginteger s;
Biginteger t;
s = t;
(b) the fact that all constructed objects are automatically destroyed
(c) the fact that the copy constructor is invoked if an object is passed by value to a function
(d) the fact that the copy constructor is not invoked when a parameter is passed by reference
(e) the fact that the copy constructor is used to copy a return value to the caller.
И на крајот
Supply a constructor Biginteger(string) that reads a sequence of digits from a string. Overload + and - operators to add and subtract the digit sequences. Overload the stream operators << and >>. Demonstrate all these functions and operators.

Така да баги е комплицирана затоа барав помош да не има некој случајно готов код.


Еве некој има напраено нешто само не го разбирам баш , и има некој грешки.
http://www.daniweb.com/forums/thread30747.html
 
luge dajte nekoe asalno programce za da mozam da kompajliram C pls
DEV c++ me jebe isto ko i visio
 
C++ e напишав е па малку комплицирано е :) затоа ми треба.
Инаку ова Biginteger е карактеристично за JAVA ама мене ми го дадоа за C++ да го направам нешто.

Define a class Biginteger that stores arbitrary large integers, by keeping their digits in a dynamically allocated array of integers.
Supply the "big three" memory management functions.
И потоа треба да се демонстрира
(a) the difference between initialization
Biginteger s;
Biginteger t = s;
and assignment
Biginteger s;
Biginteger t;
s = t;
(b) the fact that all constructed objects are automatically destroyed
(c) the fact that the copy constructor is invoked if an object is passed by value to a function
(d) the fact that the copy constructor is not invoked when a parameter is passed by reference
(e) the fact that the copy constructor is used to copy a return value to the caller.
И на крајот
Supply a constructor Biginteger(string) that reads a sequence of digits from a string. Overload + and - operators to add and subtract the digit sequences. Overload the stream operators << and >>. Demonstrate all these functions and operators.

Така да баги е комплицирана затоа барав помош да не има некој случајно готов код.


Еве некој има напраено нешто само не го разбирам баш , и има некој грешки.
http://www.daniweb.com/forums/thread30747.html

Почнувај сам, консултирај се кога ќе заглавиш. Мене ме мрзи тоа. Тоа е тоа, преоптоварување на оператори, како што и мислев. Тури ме на скајп ќе средиме нешто.

Што е invoked?

Мене демонстрацијата не ми е јасна. Шо подразбираш под тоа?
 
Почнувај сам, консултирај се кога ќе заглавиш. Мене ме мрзи тоа. Тоа е тоа, преоптоварување на оператори, како што и мислев. Тури ме на скајп ќе средиме нешто.

Што е invoked?

Мене демонстрацијата не ми е јасна. Шо подразбираш под тоа?

daj be i ja da turam na skype mene C nisho ne mi e jasno u pm
 
Почнувај сам, консултирај се кога ќе заглавиш. Мене ме мрзи тоа. Тоа е тоа, преоптоварување на оператори, како што и мислев. Тури ме на скајп ќе средиме нешто.

Што е invoked?

Мене демонстрацијата не ми е јасна. Шо подразбираш под тоа?


Готово ја напрајв :vozbud::vozbud: ако сакаш ќе го ставам кодот за пример да му се најди на некој :)
 
Стави го тука. Ја завршив со С++ ама секогаш постои варијанта дека ќе ми треба.
 
ne be eve i so ovoj noviot program sto mi go dade skrstevsky pak istata greska i toa ne e vo sintaksa tuka koa ke se ranuva imate vnesete 2 broja i vnesuvas eden i enter i se koci cel komp i dava greska please send report ona standardnoto od windows! a eve go kodot


#include <stdio.h>
int main ()
{
int prv, vtor, vkupno, dec;
printf ("vnesi dva broja");
scanf ("%d","%d", &prv, &vtor);
printf ("preciznost na pecatenje broj na decimali");
scanf ("%d","%d", &vkupno, &dec);
printf("%d + %d=%0*d\n", prv,vtor,vkupno,prv + vtor);


return 0;
}
 
Еве ја програмата

Код:
#ifndef bigint_h
#define bigint_h

#include <iostream>
using std::ostream;

class bigint
{
      friend ostream &operator<<(ostream &, const bigint &);
      
public:
       bigint ( long = 0);
       bigint ( const char*);
       bigint operator+( const bigint &) const;
       bigint operator+( int ) const;
       bigint operator+( const char*) const;
       bigint operator*( const bigint&) const;
       bigint operator*( int ) const;
       bigint operator*( const char*) const;
       bigint operator/( const bigint&) const;
       bigint operator/( int ) const;
       bigint operator/( const char*) const;
private:
       short integer[30];
};
#endif
#include <cctype>
#include <cstring>
#include "bigint.h"

bigint::bigint(long value)
{
       for (int i=0; i <30; i++)
            integer [i] = 0;      
       
       for (int j=29; value !=0 && j>= 0; j--)
       {
           integer[j]=value % 10;
           value /=10;
       }
}

bigint::bigint(const char *string)
{
        for ( int i=0; i< 30; i++)
             integer[i] = 0;
        int lenght = strlen(string);
        for (int j=30 - lenght, k = 0; j <=29; j++, k++)
             if (isdigit(string[k]))
                 integer [j]= string [k] -'0';
}

bigint bigint::operator+(const bigint &op2) const
{
           bigint temp;
           int carry=0;
           for (int i=29; i>=0; i--)
           {
               temp.integer[i] = integer [i]+ op2.integer[i]+carry;
               if (temp.integer[i]>9)
               {
                   temp.integer[i] %= 10;
                   carry = 1;
                }
                else
                    carry = 0;
            }
return temp;            
}                                                               

bigint bigint::operator+(int op2)const
{
       return *this + bigint(op2);
}
bigint bigint::operator+(const char *op2)const
{
       return *this + bigint(op2);
}

ostream& operator << (ostream &output, const bigint &num)
{
         int i;
         for (i=0; (num.integer[i] == 0) && (i<30); i++);
         if (i==30)
             output << 0;
         else
             for ( ;i <30 ;i++)
                  output << num.integer[i];
         return output;
}                       
                                                     

#include <iostream>

using std::cin;
using std::cout;

int main()
{
    bigint n1(125);
    bigint n2(50);
    bigint n3("999999999999999999999999999999");
    bigint n4("1");
    bigint n5;
    
    cout << "\n\nN1 is " << n1 << "\n\nN2 is " << n2
         << "\n\nN3 is " << n3 << "\n\nN4 is" << n4
         << "\n\nN5 is " << n5 << "\n\n";
         
n5=n1+n2;
cout << n1 << " + " << n2 << " = " << n5 << "\n\n";
cout << n3 << " + " << n4 << " = " << (n3+n4) <<"\n\n";
cout << "\n\n\t";
system( "pause");
return 0;
}

Jас уште еден семестар треба да учам :) ова е почетокот на то што иди fucking advanced programing
 
Еве и за другата задача решение :)

Given set of points in the plane, you have to write a program in C++ that computes the following values:
1. The minimal distance between two points.
2. The maximal distance between two points.
3. The largest area of a triangle which has vertices at given points.
4. The area of a convex hull of the set of points.

Код:
#include <iostream>
#include <math>
using namespace std;

#define N_PNT   50

typedef struct TPoint {
  int x;
  int y;
} TPT;

TPT Points[] =
   {{73, 58}, {45, 19}, {89,  6}, {22, 40}, {92, 16}, {65, 66},
    {55,  4}, {45, 18}, {64, 13}, {56, 81}, {73, 33}, {58, 40},
    {40, 71}, {90, 60}, {16, 47}, {6,  52}, {62, 91}, {90, 83},
    {69, 78}, {61, 62}, {71, 57}, {32, 53}, {67, 91}, {83, 89},
    {14, 53}, {45, 35}, {11,  6}, {9,  50}, {70, 65}, {50, 47},
    {65, 57}, {40, 68}, {44, 40}, {77, 61}, {27, 59}, {27, 54},
    {94, 89}, {90, 88}, {61, 66}, {72,  4}, {11, 41}, {3,  74},
    {44, 33}, {47, 79}, {68, 33}, {32, 64}, {66, 23}, {55, 12},
    {37, 54}, {28, 95}};

double GetDistancePoints( TPT A, TPT B )
{
  return( sqrt( pow( (B.x - A.x), 2 ) + pow( (B.y - A.y), 2 ) ) );
}

int main(int argc, char* argv[])
{
  int    i, j, k,
         MaxI, MaxJ, MinI, MinJ, MaxSI, MaxSJ, MaxSK;
  double MaxD, MinD, D, A, B, C, P, S, MaxS;

  for ( i = 0; i < N_PNT; i++ )
    for ( j = i + 1; j < N_PNT; j++ ) {
      D = GetDistancePoints( Points[i], Points[j] );
      if ( i == 0 && j == 1 ) {
        MaxD = MinD = D;
        MaxI = MinI = 0;
        MaxJ = MinJ = 1;
      }
      else {
        if ( D > MaxD ) {
          MaxD = D;
          MaxI = i;
          MaxJ = j;
        }

        if ( D < MinD ) {
          MinD = D;
          MinI = i;
          MinJ = j;
        }
      }
    }

  for ( i = 0; i < N_PNT; i++ )
    for ( j = i + 1; j < N_PNT; j++ )
      for ( k = j + 1; k < N_PNT; k++ ) {
        A = GetDistancePoints( Points[i], Points[j] );
        B = GetDistancePoints( Points[i], Points[k] );
        C = GetDistancePoints( Points[j], Points[k] );
        P = (A + B + C) / 2;
        S = sqrt( P * (P - A) * (P - B) * (P - C) );

        if ( i == 0 && j == 1 && k == 2 ) {
          MaxS = S;
          MaxSI = i;
          MaxSJ = j;
          MaxSK = k;
        }
        else
          if ( MaxS < S ) {
            MaxSI = i;
            MaxSJ = j;
            MaxSK = k;
            MaxS = S;
          }
      }

  cout << "1) MinDistancePoints = " << MinD << " between points P"
       << MinI + 1 << "(" << Points[MinI].x << ", "
       << Points[MinI].y << ") and "
       << "P" << MinJ + 1 << "(" << Points[MinJ].x << ", "
       << Points[MinJ].y << ");" << endl;

  cout << "2) MaxDistancePoints = " << MaxD << " between points P"
       << MaxI + 1 << "(" << Points[MaxI].x << ", "
       << Points[MaxI].y << ") and "
       << "P" << MaxJ + 1 << "(" << Points[MaxJ].x << ", "
       << Points[MaxJ].y << ");" << endl;

  cout << "3) Largest area of triangle = " << MaxS << " with points P"
       << MaxSI + 1 << "(" << Points[MaxSI].x << ", "
       << Points[MaxSI].y << ") and "
       << "P" << MaxSJ + 1 << "(" << Points[MaxSJ].x << ", "
       << Points[MaxSJ].y << ") and "
       << "P" << MaxSK + 1 << "(" << Points[MaxSK].x << ", "
       << Points[MaxSK].y << ");" << endl;

  system( "pause" );

  return 0;
}
 
ne be eve i so ovoj noviot program sto mi go dade skrstevsky pak istata greska i toa ne e vo sintaksa tuka koa ke se ranuva imate vnesete 2 broja i vnesuvas eden i enter i se koci cel komp i dava greska please send report ona standardnoto od windows! a eve go kodot


#include <stdio.h>
int main ()
{
int prv, vtor, vkupno, dec;
printf ("vnesi dva broja");
scanf ("%d","%d", &prv, &vtor);
printf ("preciznost na pecatenje broj na decimali");
scanf ("%d","%d", &vkupno, &dec);
printf("%d + %d=%0*d\n", prv,vtor,vkupno,prv + vtor);


return 0;
}

scanf ("%d","%d", &prv, &vtor);
printf ("preciznost na pecatenje broj na decimali");
scanf ("%d","%d", &vkupno, &dec);

не се прави тоа така :)

вака може:

scanf ("%d , %d", &prv, &vtor);
printf ("preciznost na pecatenje broj na decimali");
scanf ("%d , %d", &vkupno, &dec);
 
brat skontav i jas toa u meguvreme ama i taka nejke samo sho veke nejke za ovaa zadaca nego nesaka nitu za niedna novo pisana samo starite sho veke rabotea!!!
 
daj ziti se samo save as da kliknam za mingw vo deka na sajtov se gubam...btw sto pati imam simnato mingw i sve neso im fali taka daj mi direknten link od toa tvoeto mingw pls
 

Kajgana Shop

Back
На врв Bottom