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

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

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

Восстановить пароль

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

Ответ
 
Опции темы Поиск в этой теме
Старый 03.06.2011, 22:52   #1
Maria_Добрая
Пользователь
 
Регистрация: 03.06.2011
Сообщений: 19
Смущение Кто может помочь с кодом?

Кто может помочь с кодом на С++? Пишите в ЛС.
Maria_Добрая вне форума Ответить с цитированием
Старый 03.06.2011, 23:44   #2
xwicked
Участник клуба
 
Аватар для xwicked
 
Регистрация: 21.03.2010
Сообщений: 1,508
Лампочка

Цитата:
Сообщение от Maria_Добрая Посмотреть сообщение
Кто может помочь с кодом на С++? Пишите в ЛС.
Думаю, что многим будет интересно с Вами пообщаться здесь, на форуме. Так что - проблемный код в студию!
Google - лучший помощник программиста.
---
моя лаборатория | мой FaceBook

Последний раз редактировалось xwicked; 04.06.2011 в 09:51.
xwicked вне форума Ответить с цитированием
Старый 04.06.2011, 11:24   #3
Maria_Добрая
Пользователь
 
Регистрация: 03.06.2011
Сообщений: 19
Печаль (((

Проблема в том, что код слишком длинный((( я не могу его скинуть
Maria_Добрая вне форума Ответить с цитированием
Старый 04.06.2011, 11:34   #4
Alex11223
Старожил
 
Аватар для Alex11223
 
Регистрация: 12.01.2011
Сообщений: 19,500
По умолчанию

Если код настолько длинный, то вряд ли кто-то будет в нем бесплатно и даже без указания в чем проблема или примерного места ошибки разбираться. Но выложить можно на pastebin.com
Ушел с форума, https://www.programmersforum.rocks, alex.pantec@gmail.com, https://github.com/AlexP11223
ЛС отключены Аларом.
Alex11223 вне форума Ответить с цитированием
Старый 04.06.2011, 11:50   #5
Maria_Добрая
Пользователь
 
Регистрация: 03.06.2011
Сообщений: 19
По умолчанию

# ifndef SHIP_H
# define SHIP_H
#include <windows.h>

#include <set>
#include <map>
#include <string>
//include "CyrIOS.h"

#define N 10

struct Cell;
typedef std::set<Cell> CellSet;

struct Cell
{
Cell (int _r=0, int _c=0):row(_r), col(_c) {}
bool InSet(const CellSet&) const;
bool operator<(const Cell&) const;
int row;
int col;
};

struct Rect
{
Rect() {}
Rect(Cell _It, Cell _rb):It(_It), rb(_rb) {FillCset();}
void FillCset();
bool Intersect(const CellSet& cs) const;
Cell It;
Cell rb;
CellSet cset;
};

class Ship
{
friend class UserNavy;
friend class RobotNavy;
public:
Ship():nDeck(0), nLiveDeck(0) {}
Ship(int, std::string, Rect);
protected:
Rect place;
std::string name;
int nDeck;
int nLiveDeck;
};
Maria_Добрая вне форума Ответить с цитированием
Старый 04.06.2011, 11:51   #6
Maria_Добрая
Пользователь
 
Регистрация: 03.06.2011
Сообщений: 19
Смущение попробую так выложить

[QUOTE=Maria_Добрая;817170]# ifndef SHIP_H
# define SHIP_H
#include <windows.h>

#include <set>
#include <map>
#include <string>
//include "CyrIOS.h"

#define N 10

struct Cell;
typedef std::set<Cell> CellSet;

struct Cell
{
Cell (int _r=0, int _c=0):row(_r), col(_c) {}
bool InSet(const CellSet&) const;
bool operator<(const Cell&) const;
int row;
int col;
};

struct Rect
{
Rect() {}
Rect(Cell _It, Cell _rb):It(_It), rb(_rb) {FillCset();}
void FillCset();
bool Intersect(const CellSet& cs) const;
Cell It;
Cell rb;
CellSet cset;
};

class Ship
{
friend class UserNavy;
friend class RobotNavy;
public:
Ship():nDeck(0), nLiveDeck(0) {}
Ship(int, std::string, Rect);
protected:
Rect place;
std::string name;
int nDeck;
int nLiveDeck;
};
Maria_Добрая вне форума Ответить с цитированием
Старый 04.06.2011, 11:53   #7
Maria_Добрая
Пользователь
 
Регистрация: 03.06.2011
Сообщений: 19
По умолчанию

# endif /* SHIP_H */
//Ship.cpp

#include <iostream>
#include <string>
#include <algorithm>
#include "Ship.h"
using namespace std;
bool Cell::InSet(const CellSet& cs) const
{
return (cs.count(Cell(row. col))>0);
}
bool Cell:perator <(const Cell& c) const
{
return ((row<c.row) || ((row==c.row) && (col<c.col)));
}

void Rect::FillCset()
{
for (int i=It.row; i<=rb.row; i++)
for (int j=It.col; j<=rb.col; j++)
cset.insert(Cell(i,j));
}

bool Rect::Intercset(const CellSet& cs) const
{
CellSet common_cell;
set_intersection(cset.begin(), cset.end(), cs.begin(), cs.end(),
inserter(common_cell, common_cell.begin()));
return (common_cell.size()>0);
}

Ship::Ship(int _nDeck, string _name, Rect _place):
place(_place), name(_name), nDeck(_nDeck), nLiveDrck(_nDeck) {}
Maria_Добрая вне форума Ответить с цитированием
Старый 04.06.2011, 11:54   #8
Maria_Добрая
Пользователь
 
Регистрация: 03.06.2011
Сообщений: 19
По умолчанию

//Navy.h


#include "Ship.h"
#define DECK 176
#define DAMAGE 'X'
#define MISS '0'

typedef unsigned char Field[N][N];
typedef std::map<Cell, int>ShipMap;

enum CurrentState {Miss, Damage, Kill};

struct Space
{
public:
static Cell u_fire;
static Cell r_fire;
static CurrentState u_state;
static CurrentState r_state;
static int step;
};

class Navyublic Space
{
public:
Navy();
void AllocShip(int, int, std::string);
void Show() const;

int GetInt();
bool IsLive() {return (nLiveShip>0);}
Rect Shell(Rect) const;
void AddToVetoSet(Rect);

protected:
Ship ship[10];
Field ownField;
Field enemyField;
ShipMap shipMap;
CellSet vetoSet;
CellSet crushSet;
int nLiveShip;
};

class UserNavyublic Navy
{
public:
UserNavy() {Allocation();}
void Allocation();
void FireOff();
void ResultAnalys();
void GetFire();
void FillDeadZone(Rect r, Field&);
};

class RobotNavyublic Navy
{
public:
RobotNavy();
void Allocation();
void FireOff();
void ResultAnalys();
void GetFire();
private:
bool isCruchContinue;
bool upEmpty;
};
Maria_Добрая вне форума Ответить с цитированием
Старый 04.06.2011, 11:57   #9
Maria_Добрая
Пользователь
 
Регистрация: 03.06.2011
Сообщений: 19
По умолчанию

//Navy.cpp

#include <iostream>
#include <cstlib>
#include <time.h>
#include <algorithm>
#include "Navy.h"
using namespace std;

Cell Space::u_fire;
Cell Space::r_fire;
CurrentState Space::u_state=Mass;
CurrentState Space::r_state=Mass;
int Space::step=1;

string gap(int n) {return string(n, ' ');}

Navy::Navy():nLiveShip(10)
{
for (int i=0; i<N; i++)
for (int j=0; j<N; j++)
{
ownField[i][j]='.';
enemyField[i][j]='.';
}
}

Rect Navy::Shell(Rect r) const
{
Rect sh(r);
sh.It.row=(-sh.It.row<0) ? 0:sh.It.row;
sh.It.col=(-sh.It.col<0) ? 0:sh.It.col;
sh.rb.row=(++sh.rb.row>(N-1)) ? (N-1):sh.rb.row;
sh.rb.col=(++sh.rb.col>(N-1)) ? (N-1): sh.rb.col;
return sh;
}

void Navy::AddToVetoSet(Rect r)
{
for (int i=r.It.row; i<=r.rb.row; i++)
for (int j=r.It.col; j<=r.rb.col; j++)
vetoSet.insert(Cell(i,j));
}

void Navy::AllocShip(int indShip, int nDeck, string name)
{
int i,j;
Cell It, rb;
while (1)
{
It.row=rand() % (N+1-nDeck);
It.col=rb.col=rand() % N;
rb.row=It.row+nDeck-1;
if (!Rect(It, rb).Intersect(vetoSet)) break;
}
ship[indShip]=Ship(nDeck, name, Rect(It, rb));

for (i=It.row; i<=rb.row; i++)
for (j=It.col; j<=rb.col; j++)
{
ownField[i][j]=DECK;
shipMap[Cell(i,j)]=indShip;
}

AddToVetoSet(Shell(Rect(It, rb)));
}

void Navy::Show() const
{
char rowName[10]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
string colName("1 2 3 4 5 6 7 8 9 10");
int i,j;
cout<<"________________________\n";
cout<<gap(3)<<"Мій флот"<<gap(18)<<"Флот ворога"<<endl;
cout<<gap(3)<<colName<<gap(6)<<colN ame<<endl;

for (i=0; i<N; i++)
{
//Own
string line=gap(1)+rowName[i];
for (j=0; j<N; j++)
line +=gap(1)+(char)ownField[i][j];
//Enemy
line +=gap(5)+rowName[i];
for (j=0; j<N; j++)
line +=gap(1)+(char)enemyField[i][j];
cout<<line<<endl;
}
cout<<endl;
cout<<"============================ =====\n";
cout<<step<<"."<<"Мій постріл: ";
step++;
}

int Navy::GetInt()
{
int value;
while (true)
{
cin>>value;
if ('\n'==cin.peek()) {cin.get(); break;}
else
{
cout<<"Повторіть введення колонки (очікується ціле число):"<<endl;
cin.clear();
while (cin.get() != '\n') {};
}
}
return value;
}

void UserNavy::Allocation()
{
srand((unsignet)time(NULL));
AllocShip(0, 4, "Авіаносець 'Варяг'");
AllocShip(1, 3, "Лінкор 'Муромець'");
AllocShip(2, 3, "Лінкор 'Микитович'");
AllocShip(3, 2, "Крейсер 'Чудний'");
AllocShip(4, 2, "Крейсер 'Добрий'");
AllocShip(5, 2, "Крейсер 'Справедливий'");
AllocShip(6, 1, "Міноносець 'Хоробрий'");
AllocShip(7, 1, "Міноносець 'Ушлий'");
AllocShip(8, 1, "Міноносець 'Моторний'");
AllocShip(9, 1, "Міноносець 'Сміливий'");
vetoSet.clear();
}

void UserNavy::FillDeadZone(Rect r, Field& field)
{
int i,j;
Rect sh=Shell(r);
for (i=sh.It.row, j=sh.It.col; j<=sh.rb.col; j++)
if (sh.It.row<r.It.row) field[i][j]=' ';
for (i=sh.rb.row, j=sh.It.col; j<=sh.rb.col; j++)
if (sh.rb.row>r.rb.row) field[i][j]=' ';
for (j=sh.It.col, i=sh.It.row; i<=sh.rb.row; i++)
if (sh.It.col<r.It.col) field[i][j]=' ';
for (j=sh.rb.col. i=sh.It.row; i<=sh.rb.row; i++)
if (sh.rb.col>r.rb.col) field[i][j]=' ';
}
Maria_Добрая вне форума Ответить с цитированием
Старый 04.06.2011, 11:57   #10
Maria_Добрая
Пользователь
 
Регистрация: 03.06.2011
Сообщений: 19
По умолчанию

void UserNavy::FireOff()
{
string capital_letter="ABCDEFGHIJ";
string small_letter="abcdefghij";
unsigned char rowName;
int colName;
int row;
int col;

bool success=false;
while (!success)
{
cin>>rowName;
row=capital_letter.find(rowName);
if (-1==row) row=small_letter.find(rowName);
if (-1==row) {cout<<"Помилка. Повторіть ввід.\n"; continue'}
colName=GetInt();
col=colName-1;
if ((col<0)||(col>9))

cout<<"Помилка. Повторіть ввід.\n"; continue;
}

success=true;
}

u_fire=Cell(row, col);
}

void UserNavy::ResultAnalys()
{
//r_state;
//u_fire;
switch(r_state)
{
case Maiss:
enemyField[u_fire.row][u_fire.col]=MISS;
break;
case Damage:
enemyField[u_fire.row][u_fire.col]=DAMAGE;
crushSet.insert(u_fire);
break;
case Kill:
enemyField[u_fire.row][u_fire.col]=DAMAGE;
crushSet.insert(u_fire);
Rect kill;
kill.It=*crushSet.begin();
kill.rb=*(-crushSet.end());
FillDeadZone(kill, enemyField);
crushSet.clear();
}
}
Maria_Добрая вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Кто может помочь разобраться с кодом!(Basic) danbes1 Помощь студентам 10 07.04.2011 20:58
Кто может помочь..... teres C++ Builder 1 18.03.2011 17:59
Может кто помочь с заданиями? fatalistika Фриланс 15 30.12.2010 08:52
Кто может помочь с программой codemasters Фриланс 2 28.11.2010 16:41