Форум: Форум C++Разное
Новые темы: 00
Объектно-ориентированное программирование на PHP. Авторы: Кузнецов М.В., Симдянов И.В. Самоучитель PHP 5 / 6 (3 издание). Авторы: Кузнецов М.В., Симдянов И.В. MySQL 5. В подлиннике. Авторы: Кузнецов М.В., Симдянов И.В. PHP Puzzles. Авторы: Кузнецов М.В., Симдянов И.В. C++. Мастер-класс в задачах и примерах. Авторы: Кузнецов М.В., Симдянов И.В.
ВСЕ НАШИ КНИГИ
Консультационный центр SoftTime

Форум C++

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум Структурный форум

тема: Классы в С++
 
 автор: metiS   (29.03.2010 в 23:07)   письмо автору
 
 

Что здесь не так ??? ( spysok - это список =) )


#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
class spysok
{
private:
int a;
spysok *nach;
spysok *next;
public:
spysok(spysok&ch2)
{
nach=this;
*nach=ch2;
}
spysok(int b)
{
nach=this;
next=NULL;
a=b;
}
spysok()
{
nach=this;
next=NULL;
a=0;
}
void add_el(int b)
{
spysok *var=nach;
while(var->next)
var=var->next;
var->next=new spysok;
var->next->a=b;
var->next->nach=nach;
var->next->next=NULL;
}
void print()
{
cout<<"spysok:"<<endl;
spysok *var=nach;
while(var->next)
{
cout<<var->a<<endl;
var=var->next;
}
cout<<var->a<<endl;
}
int num()
{
spysok *var=nach;
int n=1;
while(var->next)
{
n++;
var=var->next;
}
return n;
}
~spysok()
{
nach->next=NULL;
nach->a=0;
}
spysok &operator = (spysok &var)
{
nach->~spysok();
spysok *var2=&var;
var2=var2->nach;
while(var2->next)
{
nach->add_el(var2->a);
var2=var2->next;
}
nach->add_el(var2->a);
return *nach;
}
spysok &operator =(int b)
{
nach->~spysok();
nach->a=b;
return *nach;
}
void del_el()
{
nach=next;
a=0;
spysok *var2=nach;
while(var2->next)
{
var2->nach=nach;
var2=var2->next;
}var2->nach=nach;
}
bool operator == (spysok &a)
{
spysok *var=nach;
spysok *var2=&a;
if(a.num()==nach->num())
{
if(a.a==nach->a)
{
while (var->next)
{
var=var->next;
var2=var2->next;
if(var2->a!=var->a)
return false;
}
}else
{
return false;
}
return true;
}
bool operator != (spysok &a)
{
if(*nach==a)
return false;
else
return true;
}
spysok & operator += (spysok&b)
{
spysok *var=new spysok;
*var=b;
spysok *var2=nach;
while(var2->next)
var2=var2->next;
var2->next=var;
while(var->next)
{
var->nach=nach;
var=var->next;
}
var->nach=nach;
return *nach;
}
spysok & operator += (int a)
{
nach->add_el(a);
return *nach;
}
friend spysok & operator +(spysok &a,spysok &b);
friend spysok & operator +(int a,spysok &b);
friend spysok & operator +(spysok &a,int b);
int operator[](int i)
{
spysok *var=nach;
int i2=1;
while(var->next)
{
if(i2==i)
{
return var->a;
}
i++;
var=var->next;
}
if(i2==i)
{
return var->a;
}
throw("nemaje elementa");
}
int poisk(int a)
{
spysok *var=nach;
int i=1;
while(var->next)
{
if(var->a==a)
return i;
i++;
var=var->next;
}
};
spysok & operator + (spysok &a, spysok &b)
{
spysok *c=new spysok;
spysok *d=new spysok;
*c=a;
*d=b;
return *c+=*d;
}
spysok & operator + (int a, spysok &b)
{
spysok *c=new spysok;
*c=b;
c->add_el(a);
return *c;
}
spysok & operator + (spysok &a,int b)
{
spysok *c=new spysok;
*c=a;
c->add_el(b);
return *c;
}
void main ()
{
spysok ch1=5;
spysok ch2=ch1;
ch2.add_el(15);
ch2.add_el(10);
ch2.add_el(-1);
ch2.add_el(0);
ch2.add_el(45);
cout<<"poisk:"<<ch2.poisk(15)<<endl;
cout<<"poisk:"<<ch2.poisk(-1)<<endl;
cout<<"poisk:"<<ch2.poisk(0)<<endl;
cout<<"poisk:"<<ch2.poisk(125)<<endl;
ch2+=125;
ch2.print();

}

  Ответить  
Rambler's Top100
вверх

Rambler's Top100 Яндекс.Метрика Яндекс цитирования