Hi!
I'm new to this forum and joined as i had some doubts regarding c++. I've been studying c++ at school for about 8 months now and now we've been given a project to complete.
Here's the topic:
http://www.cbse-sample-papers.blogspot.com/2008/09/computer-science-project-c-class-xii.html

I've decided to make a Manager mode sort of a program for one of the English Premier League sides.

Our teacher has not taught us a few things, so i need some help. I haven't started with my project as i have some queries i need cleared first.

1)i wanted to create a welcome screen. can i put a photo in it. if so, what is the function and header file i have to use?

2)Since its a manager mode sort of a program, i'll have to update the file week by week. So, i would need an iteration statement for incrementing the weeks. But suppose if the user wants to save the game halfway through, how do i re-start the game from the point he saved it at?
Example the for loop was broken at 20 instead of the default 52, how do i start the loop again from 20 to 52? It would matter since each week, there will be a different opponent.

3)During simulation of games, i'm planning to give each team a different skill level. So, i'll have to randomise the scoreline based on that skill level. Also, i have to randomise the scorer. How would i go about that. (I don't know anything about generating a random number, but i think there is such a function?)

I understand if you don't understand the program now, i will put up some codes in a couple of days time.

Thanks in advance.

Well, I don't think you can put a photo on the welcome screen, but you can definitely create a good welcome screen using graphics.h. Few fonts are also available. There is a function called rand() defined in stdlib.h which can be used to randomize as you want. For example if you use array index to represent various scorers just give rand()%(no. of players) now, random players within the limit would be generated. I don't get what you mean in the second question.

Give your objectives in detail.

Give your objectives in detail.

I solved the 2nd question myself. Thanks for the rest. But, please can you tell me something more about graphisc.h and it's functions?

Thanks again!

Actually what do you want to do??? There's a lot which can be done, even cursors,shapes can be drawn using graphics.h, fonts may be changed and back ground colour added

First you must initiate graphics mode, The best thing to do is refer a book for initiating graphics mode and loading graphics drivers and then refer to the help feature in the editor for functions

Initially, i wanted the welcome screen to be something like:

Welcome to Manchester United Manager Mode

{man utd logo here}

Press any key to continue...

But, since logo can't be done, i'll try doing something else to make it look attractive..

Thanks anyway. +rep

I found the SDL libraries to be great for graphics. They are really easy to use and there are lots of great tutoials on using them

I will post a model opening screen

void first()
{
	int gd=DETECT,gm;
	initgraph(&gd,&gm,"c:\\tc\\bgi");
	setcolor(CYAN);
	setbkcolor(15);
	settextstyle(4,0,8);
	outtextxy(40,50,"Manchester United");
	outtextxy(180,120,"Manager mode");
	setcolor(YELLOW);

	settextstyle(1,0,1);
	setcolor(RED);
	outtextxy(480,350,"Made By:");
	setcolor(GREEN);
	outtextxy(480,370,"name1");
	outtextxy(480,390,"name2");
	outtextxy(480,410,"name3");
	outtextxy(480,430,"name4");

	getch();
	restorecrtmode();
}

configure the coordinates as you may require.

Thanks,but i've already made the welcome screen.
I've made the whole program but i'm getting some garbage error.
It's a pretty big program so i won't post the code here. If i post parts of the code, you guys won't understand it. Everything is inter connected.
What should i do?

Learn to DEBUG!!!

There are many debuggers out there learn to use them and run your programmer in debugger mode.

It's a pretty big program so i won't post the code here. If i post parts of the code, you guys won't understand it. Everything is inter connected.
What should i do?

How big is 'big'? We're not afraid of a bit code ;)
Did you use functions and/or classes? If so: you could post the functions that give you troubles.
If not: Learn to use them!

I guess i solved one of the problems. A stupid silly mistake by me.

and i think i've got most of it solved if I get to know how to run a particular function only the first time the program is run. Is there a way to do that?
thanks...

BTW:here's the file if anyone wants it. it's a bit messy!
http://rapidshare.com/files/232905469/MANUTDHH.CPP.html

Don't link me to rapidshare. That makes me very sad :(

Just post the code here. Do it like this:

[code=cplusplus] Paste your code here

[/code]

Oh well..you asked for it.

#include<fstream.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<graphics.h>
int query=1;
class manutd
{
public:
char pname[50];
int goals,salary;
}player[17],rplayer[17],r2player[17];

class teams
{public:
char team_name[50];
int skill;
}team[19];

class trnsfr
{
public:
char tname[50];
int tsal;
}tplayer[15];

class general
{
public:
int week;
int mskill;
int tot_goals;
}ob,ob2;

void welcome_screen()
     {
	clrscr();
	textcolor(RED);
	gotoxy(10,10);
	cout<<"**************** W E L C O M E  *********************** ";
	gotoxy(15,12);
	cout<<"*** T O  M A N C H E S T E R   U N I T E D  *** " ;
	gotoxy(10,14);
	textcolor(RED);
	cout<<"******* C L U B  M A N A G E M E N T  ******* ";
	gotoxy(28,16);
	textcolor(RED);
	gotoxy(10,20);
	cout<<"";

	textcolor(RED+BLINK);
	gotoxy(20,30);
	cout<<" *** PRESS ANY KEY TO CONTINUE***";
	getch();
	return;
     }
void initiate()
{
//Player Names
strcpy(r2player[1].pname,"Edwin Van Der Sar");
strcpy(r2player[2].pname,"Patrice Evra");
strcpy(r2player[3].pname,"John O'Shea");
strcpy(r2player[4].pname,"Rio Ferdinand");
strcpy(r2player[5].pname,"Nemanja Vidic");
strcpy(r2player[6].pname,"Darren Fletcher");
strcpy(r2player[7].pname," Michael Carrick");
strcpy(r2player[8].pname," Cristiano Ronaldo");
strcpy(r2player[9].pname," Ryan Giggs");
strcpy(r2player[10].pname," Carlos Tevez");
strcpy(r2player[11].pname," Wayne Rooney");
strcpy(r2player[12].pname," Ben Foster");
strcpy(r2player[13].pname," Rafael De Silva");
strcpy(r2player[14].pname," Ji Sung Park");
strcpy(r2player[15].pname," Dimitar Berbatov");
strcpy(r2player[16].pname," Johny Evans");
strcpy(r2player[17].pname," Paul Scholes");
ob.week=0;
ob.tot_goals=0;
ob2.week=0;
ob2.tot_goals=0;
query++;
//initiations of goals from 0
for(int i=1;i<=17;i++)
{
r2player[i].goals=0;
}

//specify salary given to each player
r2player[1].salary=5000;
r2player[2].salary=3000;
r2player[3].salary=4000;
r2player[4].salary=5000;
r2player[5].salary=4500;
r2player[6].salary=3500;
r2player[7].salary=4000;
r2player[8].salary=7500;
r2player[9].salary=6000;
r2player[10].salary=5000;
r2player[11].salary=6500;
r2player[12].salary=2500;
r2player[13].salary=2500;
r2player[14].salary=3000;
r2player[15].salary=4000;
r2player[16].salary=3000;
r2player[17].salary=5000;
//ob.tot_sal=0;
//for(int j=1;j<=17;j++)
//{
//ob.tot_sal+=player[j].salary;
//}


//Tranfer Players
strcpy(tplayer[1].tname,"Roque Santa Cruz");
tplayer[1].tsal=3000;
strcpy(tplayer[2].tname,"Lionel Messi");
tplayer[2].tsal=6500;
strcpy(tplayer[3].tname,"Amir Zaki");
tplayer[3].tsal=3000;
strcpy(tplayer[4].tname,"Ricardo Kaka");
tplayer[4].tsal=5500;
strcpy(tplayer[5].tname,"Ibrahamovic");
tplayer[5].tsal=4500;
strcpy(tplayer[6].tname,"Luka Modric");
tplayer[6].tsal=4000;
strcpy(tplayer[7].tname,"Peter Crouch");
tplayer[7].tsal=3000;
strcpy(tplayer[8].tname,"Bastian Schweinsteiger");
tplayer[8].tsal=4000;
strcpy(tplayer[9].tname,"Deco");
tplayer[9].tsal=4500;
strcpy(tplayer[10].tname,"Franck Ribery");
tplayer[10].tsal=5000;
strcpy(tplayer[11].tname,"Karim Benzema");
tplayer[11].tsal=2500;
strcpy(tplayer[12].tname,"Mamadou Sakho");
tplayer[12].tsal=2000;
strcpy(tplayer[13].tname,"Wilson Palacios");
tplayer[13].tsal=2500;
strcpy(tplayer[14].tname,"Douglas Costa");
tplayer[14].tsal=2500;
strcpy(tplayer[15].tname,"Nicolas Bertolo");
tplayer[15].tsal=3000;

//EPL Teams:
strcpy(team[1].team_name,"Liverpool");
team[1].skill=18;
strcpy(team[2].team_name,"Chelsea");
team[2].skill=18;
strcpy(team[3].team_name,"Arsenal");
team[3].skill=17;
strcpy(team[4].team_name,"Aston Villa");
team[4].skill=15;
strcpy(team[5].team_name,"Everton");
team[5].skill=14;
strcpy(team[6].team_name,"Fulham");
team[6].skill=13;
strcpy(team[7].team_name,"Tottenham");
team[7].skill=15;
strcpy(team[8].team_name,"West Ham United");
team[8].skill=13;
strcpy(team[9].team_name,"Manchester City");
team[9].skill=15;
strcpy(team[10].team_name,"Wigan Athletic");
team[10].skill=13;
strcpy(team[11].team_name,"Stoke City");
team[11].skill=12;
strcpy(team[12].team_name,"Bolton Wanderers");
team[12].skill=12;
strcpy(team[13].team_name,"Blackburn Rovers");
team[13].skill=13;
strcpy(team[14].team_name,"Portsmouth");
team[14].skill=13;
strcpy(team[15].team_name,"Sunderland");
team[15].skill=12;
strcpy(team[16].team_name,"Newcastle United");
team[16].skill=11;
strcpy(team[17].team_name,"Hull City");
team[17].skill=10;
strcpy(team[18].team_name,"Middlesbrough");
team[18].skill=9;
strcpy(team[19].team_name,"West Bromwich Albion");
team[19].skill=7;

ob.mskill=19;
}

void view_team()
{
clrscr();
ifstream fin("manutd.txt",ios::in);
for(int i=1;i<=17;i++)
{
fin.read((char*)&rplayer[i],sizeof(rplayer[i]));
}
fin.close();

textcolor(RED);
cout<<"\n\tMANCHESTER UNITED";
for(int j=1;j<=17;j++)
{
cout<<"\nPlayer Name: ";
puts(rplayer[j].pname);
cout<<"\nGoals Scored: "<<rplayer[i].goals;
}
cout<<"\n\tTotal Goals scored: "<<ob2.tot_goals;
textcolor(RED+BLINK);
cout<<"PRESS ANY KEY TO RETURN TO MENU";
getch();
}

void save()
{
clrscr();
ofstream fout("manutd.txt",ios::out|ios::app);
fout<<ob2.week;
for(int i=1;i<=17;i++)
{
fout.write((char *)&r2player[i],sizeof(r2player[i]));
}
fout.close();
cout<<" Data Saved!";
gotoxy(10,10);
textcolor(RED+BLINK);
cout<<"PRESS ANY KEY TO RETURN TO MENU";
getch();
}


void simulation()
{
clrscr();
int play[11];
ifstream weekin("manutd.txt",ios::in|ios::beg);
weekin>>ob2.week;
ob2.week++;
for(int i=1;i<=17;i++)
{
weekin.read((char*)&r2player[i],sizeof(r2player[i]));
}
weekin.close();
int n=ob2.week;
cout<<"Week Number: "<<ob2.week;
if(ob2.week>20)
{
n=ob2.week-20;
}
cout<<"\n\t Choose your team using the numbers given:";
for(int j=1;j<=17;j++)
{
cout<<"\n"<<j;
textcolor(RED);
puts(r2player[j].pname);
}
for(int h=1;h<=11;h++)
{
cin>>play[h];
if(play[h]>17 || play[h]<1)
{
cout<<"Wrong choice, Please re-enter";
cin>>play[h];
} }
clrscr();
cout<<"\n\t Your team:";
for(int g=1;g<=11;g++)
{
cout<<"\n";
puts(r2player[play[g]].pname);
cout<<"\n";
}

//scoring
int r=ob.mskill-team[n].skill;
int fg,ag;
	srand(time(NULL));
	if(r==1 || r==2)
	{
	fg=rand()%4;
	ag=rand()%3;
	}
	else if(r==3 || r==4)
	{
	fg=rand()%5;
	ag=rand()%3;
	}
	else if(r>=5 && r<=7)
	{
	fg=rand()%5+1;
	ag=rand()%2;
	}
	else
	{
	fg=rand()%6+1;
	ag=rand()%2;
	}
	ob2.tot_goals+=fg;
//player scores
int s[6];
for(int e=1;e<=fg;e++)
{
s[e]=rand()%11+1;
r2player[play[s[e]]].goals++;
}
cout<<"\n \t At full time, result: ";
cout<<"\n Manchester United "<<fg<<"-"<<ag<<" ";
puts(team[19].team_name);
cout<<"\n Scorer's for Manchester United=\n";
for(int y=1;y<=fg;y++)
{
cout<<"\n";
puts(r2player[play[s[y]]].pname);
}
getch();
return;
}

void transferweek()
{
clrscr();
char c;
int p,s,g;
cout<<"\tWeek 20";
cout<<"\nTRANSFER WEEK";
cout<<"Rules:\n";
cout<<"1)For buying a player, one player has to be sold";
cout<<"\n2)Value ofbought player has to be equal of less than\n sold player\n";
cout<<"\n Do you want to buy?(y/n)";
cin>>c;
switch(c)
{
case 'y':
case 'Y':
s=0;
break;
case 'n':
case 'N':
s=1;
break;
}
while(s=0)
{
cout<<"\nPress number next to desired player\nList of players:\n";
for(int i=1;i<=15;i++)
{
cout<<i;
puts(tplayer[i].tname);
cout<<"---"<<tplayer[i].tsal<<"\n";
}
cin>>p;
clrscr();
cout<<"\n Which player to sell?\n";
for(int q=1;q<=17;q++)
{
cout<<g;
puts(r2player[q].pname);
cout<<"---"<<r2player[q].salary<<"\n";
}
cin>>g;
if(r2player[g].salary>=tplayer[p].tsal)
{
strcpy(r2player[g].pname,tplayer[p].tname);
cout<<"\n \t Negotiations Accomplished. Congratulations!";
}
else
{}
cout<<"\n Another transfer? \n0.Yes 1.No\n";
cin>>s;
}}


void menu()
{
char ch;
clrscr();
       //textbackground(WHITE);
       textcolor(RED);
       gotoxy(30,8);
       cprintf(" N:NEXT WEEK ");
       gotoxy(30,9);
       cprintf(" V:VIEW TEAM INFORMATION \n  \r ");
       gotoxy(30,10);
       cprintf(" S:SAVE DATA \n \r ");
       gotoxy(30,11);
       cprintf(" E:EXIT \n \r ");
       ch=getch();

      switch(ch)
	   {
	     case 'n':
	     case 'N':
		if(ob2.week==19)
		{
		transferweek();
		}
		else{
		simulation();}
		break;
	     case 'v' :
	     case 'V' :
		view_team();
		break;
	     case 's':
	     case 'S':
		save();
		break;
	     case 'e':
	     case 'E':
		system("cls");
		exit(0);
	 }
}

void main()
{
clrscr();
welcome_screen();
initiate();
save();
menu();
getch();
}

Oh well..you asked for it.

I've seen worse. But you should learn how to indent your code. It makes it (a lot) easier to read. It also makes you find small bugs easier. (like missing brackets)

So is anything wrong with this code? I can't test it, I don't have a compiler from the stone age (Yes, I mean Turbo...)

If you want a function that only executes the first time you run the program, you could write a file when the program starts. If the file already exists, then your program has been ran before and so you don't execute the function.

ok,i tried that.
Listen could you look at the function save();
Pls tell me will it overwrite the existing info or add to it. thanks!

Firstly i dont think your code compiles correctly.

You have defined a class and an array of 17 members.
So they start from [0,1,2......16] Where as you have started it from 1to 17. That is one compilation mistake.

Next.

fout.write((char *)&r2player[i],sizeof(r2player[i]));

all these commands.
This are absolutely unsafe type conversion.
I think that you should use the reinterpret_cast<char*>;

void main() //This is outdated and on modern compilers its illegal.
YOUR CODE IS FILLED WITH THESE MISTAKES. I THINK YOU SHOULD CORRECT THEM FIRST.

Oh well..you asked for it.

Actually there's no need for rapidshare, and if you've big code you can always attach your source to this thread :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.