Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 19.09.2010, 15:39   #1
bpystep
Форумчанин
 
Регистрация: 25.02.2009
Сообщений: 180
По умолчанию код С++

Есть три кода, просьба их закоментить, чтобы я разобрался.

1:
Код:
// Разработать систему классов: круг, треугольник. Для круга реализовать метод получения площади. Для треугольника реализовать метод сдвига.

#include "stdafx.h";
#include "conio.h";
#include "iostream";
using namespace std;
class circle
{
  private:
	double x,y,r;
  public:
    circle(double x,double y,double r);
    double square(void);
};
double circle::square(void)
{
	 return 3.1415*r*r;
}
circle::circle(double x,double y,double r)
{
	(*this).x = x;
    (*this).y = y;
	(*this).r = r;
}

class triangle
{
private:
	double x1,y1,x2,y2,x3,y3;
public:
    triangle(double x1,double y1,double x2,double y2,double x3,double y3);
	double* getCoordinates(void);
    void action(double dx,double dy);
};
triangle::triangle(double x1,double y1,double x2,double y2,double x3,double y3)
{
	(*this).x1=x1;
	(*this).y1=y1;
	(*this).x2=x2;
	(*this).y2=y2;
	(*this).x3=x3;
	(*this).y3=y3;
}
double* triangle::getCoordinates(void)
{
	double* massCoord = new double[5];
    massCoord[0]=x1;
	massCoord[1]=y1;
	massCoord[2]=x2;
	massCoord[3]=y2;
	massCoord[4]=x3;
	massCoord[5]=y3;
	return  massCoord;
}

void triangle::action(double dx,double dy)
{
    x1=x1+dx;
	y1=y1+dy;
	x2=x2+dx;
	y2=y2+dy;
	x3=x3+dx;
	y3=y3+dy;
}
void printCoordinates(triangle* t)
{
	
    cout<<"x1= "<<(t->getCoordinates())[0]<<" y1= "<<(t->getCoordinates())[1]<<endl;
	cout<<"x2= "<<(t->getCoordinates())[2]<<" y2= "<<(t->getCoordinates())[3]<<endl;
	cout<<"x3= "<<(t->getCoordinates())[4]<<" y3= "<<(t->getCoordinates())[5]<<endl;
}

int main(void)
{
	double x,y,r;
	cout<<"Enter the coordinates of the circle (x, y) and radius:"<<endl;
	cin>>x;cin>>y;
	cin>>r;
    circle c1(x,y,r);
	cout<<"Square of circle = "<<c1.square()<<endl;

	double x1,y1,x2,y2,x3,y3,dx,dy;
	cout<<"\n\nEnter the coordinates of the triangle (x1, y1,x2,y1,x3,y3) :"<<endl;
	cin>>x1;cin>>y1;
	cin>>x2;cin>>y2;
	cin>>x3;cin>>y3;
	triangle t1(x1,y1,x2,y2,x3,y3);
	cout<<"coordinates of the origin is:"<<endl;
	printCoordinates(&t1);
	cout<<"Please enter a step shift to the triangle (dx and dy)"<<endl;
	cin>>dx;cin>>dy;
    cout<<"modified coordinates "<<endl;
	t1.action(dx,dy);
	printCoordinates(&t1);
    getch();
    return 0;
}
Запомните, вы едете в Россию, поэтому когда компьютер попросит вас набрать пароль, наберите слово "Пароль"

Последний раз редактировалось bpystep; 19.09.2010 в 15:47.
bpystep вне форума Ответить с цитированием
Старый 19.09.2010, 15:40   #2
bpystep
Форумчанин
 
Регистрация: 25.02.2009
Сообщений: 180
По умолчанию

2:
Код:
#include "stdafx.h"
#include "Stroka_8.h"
#include "iostream"


void PrintMenu()
{
  printf(
"\n0. Exit\n\
1. Enter Strings Count\n\
2. Enter String Values\n\
3. test operator + (calculate strings sum)\n\
4. test operator == (find string by a value)\n\
5. test operator = (reassign all strings with a given value)\n\
6. change strings sign\n\
\n\
Select an action and press enter: "
  );
}


void ClearStrings(Stroka** &ppStrings, int nStringsCount)
{
  if(ppStrings != NULL)
  {
    for(int i = 0; i < nStringsCount; i++)
    {
      delete ppStrings[i];
    }
    delete ppStrings;

    ppStrings = NULL;
  }
}


void EnterStringsCount(Stroka** &ppStrings, int &nStringsCount)
{
  ClearStrings(ppStrings, nStringsCount);

  std::cout << "Enter number of strings" << std::endl;
  std::cin >> nStringsCount;
  ppStrings = new Stroka*[nStringsCount];
  for(int i = 0; i < nStringsCount; i++)
    ppStrings[i] = ppStrings[i] = new Stroka_8;
}

void EnterStringValue(Stroka** ppStrings, int nStringsCount)
{
  std::cout << "Enter strings values." << std::endl;

  for(int i = 0; i < nStringsCount; i++)
  {
    char Value[20];
    printf("Enter %i value: ", i + 1);
    //std::cout << "Enter value" << endl;
    std::cin >> Value;
   
    if(ppStrings[i] != NULL)
      delete ppStrings[i];

    ppStrings[i] = new Stroka_8(Value);
  }
}

void StringsSumma(Stroka** ppStrings, int nStringsCount)
{
  std::cout << "Calculate strings sum." << std::endl;

  Stroka_8 Summa;
  for(int i = 0; i < nStringsCount; i++)
  {
    Summa = Summa + *((Stroka_8*)ppStrings[i]);
  }

  //std::cout << "Summa =" << Summa.Get_str() << std::endl;
  printf("Summa = %s\n", Summa.Get_str());
}

void CheckEquation(Stroka** ppStrings, int nStringsCount)
{
  std::cout << "Test operator ==" << std::endl;

  char szValue[20];
  std::cout << "Enter value to test with: ";
  std::cin >> szValue;

  Stroka_8 val(szValue);

  for(int i = 0; i < nStringsCount; i++)
  {
    if(val == *((Stroka_8*)ppStrings[i]))
      printf("%i string = %s \n", i, val.Get_str());
  }
}

void Assignment(Stroka** &ppStrings, int nStringsCount)
{
  std::cout << "Test operator =" << std::endl;

  char szValue[20];
  std::cout << "Enter value to assign with: ";
  std::cin >> szValue;

  Stroka_8 val(szValue);

  for(int i = 0; i < nStringsCount; i++)
  {
    *((Stroka_8*)ppStrings[i]) = val;
    printf("%i string = %s \n", i, ppStrings[i]->Get_str());
  }
}

void ChangeSign(Stroka** &ppStrings, int nStringsCount)
{
  std::cout << "Test change sign operation" << std::endl;

  for(int i = 0; i < nStringsCount; i++)
  {
    ((Stroka_8*)ppStrings[i])->Change_sign();
    printf("%i string = %s \n", i, ppStrings[i]->Get_str());
  }
}



int _tmain(int argc, _TCHAR* argv[])
{
  Stroka** ppStrings = NULL;
  int nStringsCount = 0;
  char input_symbol;

  do 
  {
    PrintMenu();

    std::cin >> input_symbol;

    switch(input_symbol)
    {
    case '1':
      EnterStringsCount(ppStrings, nStringsCount);
      break;
    
    case '2':
      EnterStringValue(ppStrings, nStringsCount);
      break;
    
    case '3':
      StringsSumma(ppStrings, nStringsCount);
      break;
    
    case '4':
      CheckEquation(ppStrings, nStringsCount);
      break;
    
    case '5':
      Assignment(ppStrings, nStringsCount);
      break;
    
    case '6':
      ChangeSign(ppStrings, nStringsCount);
      break;    
    }
  } while (input_symbol != '0');

  ClearStrings(ppStrings, nStringsCount);

  return 0;
}
Запомните, вы едете в Россию, поэтому когда компьютер попросит вас набрать пароль, наберите слово "Пароль"
bpystep вне форума Ответить с цитированием
Старый 19.09.2010, 15:46   #3
bpystep
Форумчанин
 
Регистрация: 25.02.2009
Сообщений: 180
По умолчанию

3:
Код:
#include "stdafx.h"
#include "string"
#include "iostream"
#include "windows.h"

using namespace System;
using namespace std;
using namespace System::Text::RegularExpressions;
class STROKA
{
public:
	char*a;
	int len;

	STROKA() // Без параметров
	{
		
		a=new char;
		len=0;
	
	}
	STROKA(char b[])
	{
		
		len=strlen(b);
		a=new char[len+1];
		strcpy(a,b);
	}
	STROKA(char b)
	{
		
		len=1;
		a=new char[2];
		strcpy(a,&b);
	}

	STROKA(const STROKA &M)
	{
		len=M.len;
		a=new char [len+1];
		strcpy(a,M.a);
	}
	void str_len()
	{
		cout<<len; 

	}
	
	void clear()
	{
		 if(*a) delete []a ;
		*a=0;
		len=0;

	}
	void print()
	{
		cout<<a;
	}
	~STROKA()
	{ 
	}
	virtual void Conver()=0;
	virtual void operator<=(const STROKA &M)=0;
	virtual STROKA &operator=(const STROKA &M) =0;
	virtual void operator-( STROKA &M)=0;
	virtual void operator+(const STROKA &M)=0;

};
class VOS:public STROKA
{

	public:
	VOS()
	{
		a=new char;
		len=0;
	}

	VOS(char b[])
	{

			String^ text;
			for(int i=0; i<strlen(b); i++)
			{
			text+= gcnew String(&b[i],0,1);
			}

		   Regex^ rx = gcnew Regex( "[0-7]",static_cast<RegexOptions>(RegexOptions::Compiled | RegexOptions::IgnoreCase) );
				   MatchCollection^ matches = rx->Matches( text );
   if(matches->Count==strlen(b))
   {
   len=strlen(b);
   a=new char[len+1];
   strcpy(a,b);
   }
   else
   {
    a=new char;
    *a=0;
    len=0;
   } 

}
			VOS(const VOS &M)
		{
		len=M.len;
		a=new char [len+1];
		strcpy(a,M.a);
		}

			void Conver()//4 байта
			{
			 char *b=new char[100];
			 int i= -1*strtoul(a, &b, 8);
             delete []a;
             a=new char[33];
			 itoa(i,b,8);
			 strcpy(a,b);
			}
			STROKA &operator=(const STROKA &M) 
			{
			len=M.len;
			delete []a;
			a=new char[len+1];
			strcpy(a, M.a);
			return *this;
			}
			void operator-( STROKA &M)
			{
				 char *b;
				 char *b1;
				 int i= strtoul(a, &b, 8);
				 int i1= strtoul(M.a, &b1, 8);

				 i=i-i1;
				 Console::Write(i);
				
				 M.a=new char[33];
				 itoa(i,b1,8);
				 strcpy(M.a,b1);
			}
			void operator+(const STROKA &M)
			{
				 char *b;
				 char *b1;
				 int i= strtoul(a, &b, 8);
				 int i1= strtoul(M.a, &b1, 8);
				 i=i+i1;
				 Console::Write(i);
				
				 a=new char[33];
				 itoa(i,b,8);
				 strcpy(a,b);
			}
			void operator<=(const STROKA &M)
			{
				char *b;
				 int i= strtoul(a, &b, 8);
				 int i1= strtoul(M.a, &b, 8);
				 if(i<=i1)Console::WriteLine("1<=2") ; else Console::WriteLine("1>2");
			}

};

int main(array<System::String ^> ^args)
{


	
	STROKA*A[5];
	char a[100];
	int t,u;
    for(int i=0; i<5; i++)
   {
   Console::WriteLine("Введите {0}",i+1);
   cout<<">>";
   cin>>a;
   A[i]=new VOS(a);
   }
     while(true)
  {
   Console::Clear();
  for(int i=0; i<5; i++)
  {
   Console::Write("A{0}=", i+1);
   A[i]->print();
   Console::WriteLine();
      }
     Console::WriteLine("Что Вы хотите сделать?") ;
  Console::WriteLine("1. Получение длинны строки") ;
  Console::WriteLine("2. Очистка строки") ;
  Console::WriteLine("3. Изменение знака на противоположынй") ;
  Console::WriteLine("4. Присваивание (=)") ;
  Console::WriteLine("5. Арифмитическое вычитание (-)" );
  Console::WriteLine("6. Проверка на меньше или равно") ;
  Console::Write("7. Арифметическое сложение\n>>") ;

  cin>> t;
       switch(t){
  case 1:{
     Console::Write("Введите строку\n>>") ;
     cin>> u;
	 A[u-1]->str_len();
	  system("pause");
     break;
      }
		 
  case 2:
    {
     Console::Write("Введите строку\n>>") ;
     cin>> u;
	 A[u-1]->clear();
     break;
    }
  case 3:
   {
    Console::Write("Введите строку\n>>") ;
     cin>> u;
	 A[u-1]->Conver();
    break;
   }
  case 4:
   {
    Console::Write("Введите номер первой строки\n>>") ;
     cin>> u;
     Console::Write("Введите номер второй строки\n>>") ;
     cin>> t;
	 *A[u-1]:=(*A[t-1]);
	 break;
   }
  case 5:
   {
     Console::Write("Введите номер первой строки\n>>") ;
     cin>> u;
     Console::Write("Введите номер второй строки\n>>") ;
     cin>> t;
     *A[u-1]-(*A[t-1]);
     break;
   }
  case 6:
   {
    Console::Write("Введите номер первой строки\n>>") ;
     cin>> t;
     Console::Write("Введите номер второй строки\n>>") ;
     cin>> u;
     *A[t-1]<=(*A[u-1]);
     system("pause") ;
     break;
   }
   case 7:
   {
     Console::Write("Введите номер первой строки\n>>") ;
     cin>> u;
     Console::Write("Введите номер второй строки\n>>") ;
     cin>> t;
     *A[u-1]+(*A[t-1]);
     break;
   }
  }
  }

	system("pause");  
         return 0;
}
Запомните, вы едете в Россию, поэтому когда компьютер попросит вас набрать пароль, наберите слово "Пароль"
bpystep вне форума Ответить с цитированием
Старый 19.09.2010, 15:58   #4
StudentPolitech
Форумчанин
 
Аватар для StudentPolitech
 
Регистрация: 21.11.2008
Сообщений: 400
По умолчанию

Есть три девушки, просьба, привезти их ко мне, чтоб я с ними разобрался))))))
Открывай книгу (например Шилдта) и разбирайся сколько влезет, ибо код тут не сложный
Винда, KIS 2010, книжка по С/С++, остальное неважно........
StudentPolitech вне форума Ответить с цитированием
Старый 19.09.2010, 20:32   #5
bpystep
Форумчанин
 
Регистрация: 25.02.2009
Сообщений: 180
По умолчанию

я же не прошу что то писать, я прошу просто закоментить сложные моменты, неужели это так сложно...?
Буду очень благодарен
Запомните, вы едете в Россию, поэтому когда компьютер попросит вас набрать пароль, наберите слово "Пароль"
bpystep вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Код Qt в С++ Lemo Помощь студентам 0 18.09.2010 22:06
Код на Pb Arei17 Помощь студентам 12 25.08.2010 16:28
Код С++ KennyMccormickSP Общие вопросы C/C++ 5 10.05.2010 23:49
код n! на C++ diana1002 Помощь студентам 1 01.10.2009 20:34
Код игры на Паскале и на Делфи сильно отличается? Как переписать код с Паскаля в Делфи? Mclaren Помощь студентам 2 27.04.2009 22:37