Post your C/C++ Programs Here

Status
Not open for further replies.

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

^^ That is what I thought... Qt is a GUI development thing.... and aniket.awati wants something to draw lines and circles.....
 

baccilus

Cyborg Agent
Re: Post ur C/C++ Programs Here

Here's a program to calculate the computer sales man salary. Base salary, bonus rate and commission are fixed. Input of price per system and number of systems sold is from user.

Code:
#include<stdio.h>
#define BASE_SAL 2000.0
#define BONUS 200.0
#define COMMISSION 0.02

//Compiled on linux using geany

int main()
{
    int n;
    float bonus, commission, price;
    float gross_sal;
    printf("\nInput the number of systems sold  ",n);
    scanf("%d",&n);
    printf("\nInput the price of each computer  ",price);
    scanf("%f",&price);
    bonus=BONUS*n;
    commission=COMMISSION*price*n;
    gross_sal=BASE_SAL+bonus+commission;
    printf("Base salary is %f\nBonus is %f\nCommission is %f\nGross salary is %f"
    ,BASE_SAL,commission,gross_sal);
}

Gross salary is coming out to be wrong but I don't know why. Please tell if you realize that.
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

You missed a variable in your printf() statement. The bonus variable I suppose. Or BONUS. :?

Code:
#include<stdio.h>
#define BASE_SAL 2000.0
#define BONUS 200.0
#define COMMISSION 0.02

//Compiled on linux using geany

int main()
{
    int n;
    float bonus, commission, price;
    float gross_sal;
    printf("\nInput the number of systems sold  ",n);
    scanf("%d",&n);
    printf("\nInput the price of each computer  ",price);
    scanf("%f",&price);
    bonus=BONUS*n;
    commission=COMMISSION*price*n;
    gross_sal=BASE_SAL+bonus+commission;
    printf("Base salary is %f\nBonus is %f\nCommission is %f\nGross salary is %f\n"
    ,BASE_SAL,[B]bonus[/B],commission,gross_sal);
}
 

radonryder

Broken In
Re: Post ur C/C++ Programs Here

A lot of this stuff form my comp text..
I can prepare 4 my comp boards with digitXD
Well here's what I did for my school project
It basicaly an inventory tracker software...
I coded the entire thing myself..
I just custumised the menu's for a gunshop...
Im open to reviews.Tell me what you guys think of it....

>>>GUNSHOP<<<
Code:
#include<iostream.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<fstream.h>
#include<conio.h>
class staff
{
char sname[20];                                             //name of employee
int age;                                                    //age of employee
float salary;                                               //salary of employee
char job[20];                                               //type of job done(eg-cashier,delivery man)
public:

void inputs()
{
	cout<<"\nEnter New employee's Name:\n";
	gets(sname);
	cout<<"\nEnter New employee's Age:\n";
	cin>>age;
	cout<<"\nEnter New employee's job:\n";
	gets(job);
	cout<<"\nEnter New employee's Salary:\n";
	cin>>salary;
}
void displays()
{  cout<<"\n";
	cout<<sname;
	cout<<"\t\t"<<age;
	cout<<"\t\t"<<job;
	cout<<"\t\t"<<salary;
}
int searchst(char st1[20])                                          //search by name of employee
{
	if(strcmp(st1,sname)==0)
	return 0;
	else
	return 1;
}
																						  //search by job of employee
	int searchjs(char j1[20] )
{
	if(strcmp(j1,job)==0)
	return 0;
	else
	return 1;
}



};
class guns
{
char gname[20];                                                  //name of gun
char gtype[20];                                                 //type of gun(eg-pistol,shotgun,etc)
int stock;
float cost;																		//no: of guns in stock
public:

void inputg()                                                    //for inputing gun details
{
	cout<<"\nEnter Gun Name:\n";
	gets(gname);
	cout<<"\nEnter Type of Gun:\n";
	gets(gtype);
	cout<<"\nEnter Gun's Price:\n";
	cin>>cost;
	cout<<"\nEnter the Number of Guns in stock:\n";
	cin>>stock;
}

void displayg()                                                  //for displaying gun details
{  cout<<"\n";
	cout<<gname;
	cout<<"\t\t"<<gtype;
	cout<<"\t\t"<<cost;
	cout<<"\t\t"<<stock;
}
int rtstk()
{
return stock;
}

int searchgn(char gn1[20])                                       //search by gun name
{
	if(strcmp(gn1,gname)==0)
	return 0;
	else
	return 1;
}

	int searchct(char ty1[20] )                                    //search by gun type
{
	if(strcmp(ty1,gtype)==0)
	return 0;
	else
	return 1;
}

																					 //updated stock
void update(int i)
{
	 stock=stock+i;


}                                                              //updates cost
void update1()
{
float cos;
cout<<"\nEnter New price:\n";
cin>>cos;
cost=cos;
}                                                       //for purchasing
void update2(int i)
{
stock=stock-i;
}
};
guns g1;
staff s1;
void main()
{
char str[20],a;
fstream f1,f2,f3;
char ch1;
int n,ch,i,j,k,ch3;
char ch4;
cout<<"\n \n\n\nWelcome to Ammunation";
do
{  clrscr();                                                              //start of 1st do while
	cout<<"\nSelect access level";
	cout<<"\n1.Staff";
	cout<<"\n2.Admin";
	cout<<"\n3.Exit\n";
	cin>>ch;
if(ch==1)
{clrscr();
do                                                             //start of staff menu
{
cout<<"\n\nStaff Menu";                                        //gun management
cout<<"\n----------------------------------------";
cout<<"\n1.Display all Guns";
cout<<"\n2.Search by Gun Name";
cout<<"\n3.Search by Gun Type";
cout<<"\n4.Purchase Guns";
cout<<"\n5.Add more Guns";
cout<<"\n6.Update Gun details";
cout<<"\n7.Delete Guns";
cout<<"\n8.Restore deleted Guns";
cout<<"\n9.Create Backup";
cout<<"\n10.restore basckup(Caution!!->Use only if Backup File exits)";
cout<<"\n11.Clear Screen";
cout<<"\nEnter your choice\n";
cin>>ch3;
switch (ch3)
{
case 1:
			f1.open("gun1.dat",ios::in);
			f1.read((char*)&g1,sizeof(g1));
			cout<<"\nGun details";
			cout<<":\n--------------------------";
			cout<<"\nName\t"<<"\tType\t"<<"\tPrice\t"<<"\tStock\t";
			while(f1)
			{
			g1.displayg();
			f1.read((char*)&g1,sizeof(g1));
			}
			f1.close();
			break;
case 2:
			cout<<"\nEnter the Name of the Gun:\n";
			gets(str);
			f1.open("gun1.dat",ios::in);
			f1.read((char*)&g1,sizeof(g1));
			while(f1)
			{

			n=g1.searchgn(str);
			if(n==0)
				{
			cout<<"\nGun details";
			cout<<":\n--------------------------";
			cout<<"\nName\t"<<"\tType\t"<<"\tPrice\t"<<"\tStock\t";
			g1.displayg();
					break;
				}
			f1.read((char*)&g1,sizeof(g1));
			}
			if(n==1)
			{
			cout<<"\nThe Gun was Not Found";
			}
			f1.close();




			break;

case 3:  cout<<"\nEnter Type of Gun:\n";
			gets(str);
			f1.open("gun1.dat",ios::in);
			f1.read((char*)&g1,sizeof(g1));
         i=0;
			while(f1)
			{

			n=g1.searchct(str);
			if(n==0)
				{i++;
				if(i==1)
				cout<<"\nGun details";
			cout<<":\n--------------------------";
			cout<<"\nName\t"<<"\tType\t"<<"\tPrice\t"<<"\tStock\t";
				 g1.displayg();
					break;
				}
			f1.read((char*)&g1,sizeof(g1));
			}
			if(n==1)
			{
			cout<<"\nThere are no guns of "<<str<<" Type";
			}
			f1.close();
			break;

case 4:
			cout<<"\nEnter the Name of the Gun:\n";
			gets(str);
			f1.open("gun1.dat",ios::in|ios::out);
			f1.read((char*)&g1,sizeof(g1));
			k=sizeof(g1);
			while(f1)
			{
			n=g1.searchgn(str);

			if(n==0)
				{
				i=g1.rtstk();
				cout<<"\nEnter the Number of Guns to be Purchased:\n";
				cin>>j;
				if(j>i)
				{
					cout<<"\nThe Number of guns Requested is Not in Stock";
					cout<<"\nOnly "<<i<<" Are Available";
					cout<<"\nDo u still wish to buy?:/n";
					cin>>a;
					if(a=='y'||a=='Y')
					{f1.seekp(-k,ios::cur);
					g1.update2(j);

				 f1.write((char*)&g1,sizeof(g1));
					cout<<"\nPurchased ";
					}
				}
				else
				{ f1.seekp(-k,ios::cur);
					g1.update2(j);

				 f1.write((char*)&g1,sizeof(g1));
					cout<<"\nPurchased ";
				}
				 break;
				}
			f1.read((char*)&g1,sizeof(g1));

			}

			if(n==1)
			{
				cout<<"\nGun not in stock";
			}




			f1.close();



			break;
case 5:
			f1.open("gun1.dat",ios::out|ios::app);
			cout<<"\nEnter the no: of guns:\n";
			cin>>n;
			cout<<"\nEnter Gun Details:\n";
			cout<<"---------------------------------";
			for(i=0;i<n;i++)
			 {
			  g1.inputg();
				f1.write((char*)&g1,sizeof(g1));
			 }

			 f1.close();
			 break;


case 6:	cout<<"\nEnter the Name of the Gun:\n";
			gets(str);
			k=sizeof(g1);
			f1.open("gun1.dat",ios::in|ios::out);
			f1.read((char*)&g1,sizeof(g1));
			while(f1)
			{

			n=g1.searchgn(str);
			if(n==0)
				{
				 g1.update1();
				 cout<<"\nEnter the no: of guns delivered:\n";
				 cin>>i;
             f1.seekp(-k,ios::cur);
				 g1.update(i);

				 f1.write((char*)&g1,sizeof(g1));
				 cout<<"\nUpdated";
					break;
				}
			f1.read((char*)&g1,sizeof(g1));
			}
			if(n==1)
			{
			cout<<"\nThe Gun was Not Found";
			}
			f1.close();


			break;
case 7: f1.open("gun1.dat",ios::in);
		 f2.open("gun2.dat",ios::out|ios::app);
		 f3.open ("gun3.dat",ios::out|ios::app);
		 cout<<"\nEnter Name of the gun";
			gets(str);
			i=0;
			f1.read((char*)&s1,sizeof(s1));
			while(f1)
			{
			n=g1.searchgn(str);
			if(n==0)
			{i++;
			f3.write((char*)&g1,sizeof(g1));
			}
			if(n==1)
			{
			 f2.write((char*)&g1,sizeof(g1));
			}
			f1.read((char*)&g1,sizeof(g1));
			}
			f1.close();
			f2.close();
			f3.close();
			remove("gun1.dat");
			rename("gun2.dat","gun1.dat");
			if(i==0)
			cout<<"\nGun not found";
			break;

case 8: f1.open("gun1.dat",ios::out|ios::app);
		 f2.open("gun3.dat",ios::in);
		 cout<<"\nEnter the Gun's Name:\n";
		 gets(str);
		 i=0;
		 while(f2)
		 {
		 n=g1.searchgn(str);
		 if(n==0)
		 {i++;
		 f1.write((char*)&g1,sizeof(g1));
		 }
		 f2.read((char*)&g1,sizeof(g1));
		 }
		 if(i==0)
		 cout<<"\nGun not found";
		 else
		 cout<<"\nGun Restored";
		 f1.close();
		 f2.close();

			break;
case 9:  f1.open("gun1.dat",ios::in);
			f2.open("bkg.dat",ios::out|ios::app);
			f1.read((char*)&g1,sizeof(g1));

			while(f1)
			{
			f2.write((char*)&g1,sizeof(g1));
			f1.read((char*)&g1,sizeof(g1));
			}
			f2.close();
			f1.close();
			cout<<"\nBackUp Created";
			break;

case 10: remove("gun1.dat");
			rename("bkg.dat","gun1.dat");
			cout<<"\nBackup Restored";
			break;
case 11:
			clrscr();
			break;
default:cout<<"\nWrong choice\n";

}
	cout<<"\nDo u wish to continue?";
	cin>>ch4;

}while(ch4=='y'||ch4=='Y');
											 //end of staff menu
}
if(ch==2)
{

clrscr();
do
{
cout<<"\n\nAdmin Menu";                                     //employee management
cout<<"\n----------------------------------------";
cout<<"\n1.Search by Name of employee";
cout<<"\n2.Display all Staff Details";
cout<<"\n3.Display staff in a specific Catagory ";
cout<<"\n4.Update employee Details";
cout<<"\n5.Hire Staff";
cout<<"\n6.Fire Staff";
cout<<"\n7.Fired Staff History";
cout<<"\n8.Rehire staff";
cout<<"\n9.Create Backup";
cout<<"\n10.restore basckup(Caution!!->Use only if Backup File exits)";
cout<<"\n11.Clear screen";
cout<<"\nEnter Choice?";
cin>>ch3;
switch(ch3)
{
case 1:  f1.open("stf1.dat",ios::in);
			f1.read((char*)&s1,sizeof(s1));
			cout<<"\nEnter Name of the Employee:\n";
			gets(str);
			while(f1)
			{
			n=s1.searchst(str);
			if(n==0)
			{
			cout<<"\nEmployee Details";
			cout<<"\n-----------------------";
			cout<<"\nName\t"<<"\tAge\t"<<"\tJob\t"<<"\tSalary\t";
			s1.displays();
			break;
			}
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			if(n==1)
			cout<<"\nEmployee does Not Work here";
			break;

case 2:
			f1.open("stf1.dat",ios::in);
			f1.read((char*)&s1,sizeof(s1));
			cout<<"\nEmployee Details";
			cout<<"\n-----------------------";
			cout<<"\nName\t"<<"\tAge\t"<<"\tJob\t"<<"\tSalary\t";

			while(f1)
			{
			s1.displays();
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			break;

case 3:  i=0;
			f1.open("stf1.dat",ios::in);
			f1.read((char*)&s1,sizeof(s1));
			cout<<"\nPlease Enter job of the employee";
			gets(str);
			while(f1)
			{
			n=s1.searchjs(str);
			if(n==0)
			{i++;
			if(i==1)
			{
			cout<<"\nEmployee Details";
			cout<<"\n-----------------------";
			cout<<"\nName\t"<<"\tAge\t"<<"\tJob\t"<<"\tSalary\t";
			}
			s1.displays();
			}
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			if(i==0)
							break;
case 4:f1.open("stf1.dat",ios::out|ios::in);
		 cout<<"\nEnter the Employee's Name:\n";
		 gets(str);
		 i=sizeof(s1);
		 f1.read((char*)&s1,sizeof(s1));
		 while(f1)
		 {
		 n=s1.searchst(str);
		 if(n==0)
		 {
		 f1.seekg(-i,ios::cur);
		 cout<<"\nEnter New Details";
		 cout<<":\n--------------------------";
		 s1.inputs();
		 f1.write((char*)&s1,sizeof(s1));
		 break;
		 }
		 f1.read((char*)&s1,sizeof(s1));
		 }
		 if(n==1)
		 cout<<"\nEmployee does Not work here";
		 f1.close();
							break;
case 5: f1.open("stf1.dat",ios::out|ios::app);
		  cout<<"\nEnter the no: New employees:\n";
		  cin>>n;
		  cout<<"\nEnter New employee details";
        cout<<":\n--------------------------";
		  for(i=0;i<n;i++)
			{
			 s1.inputs();
			 f1.write((char*)&s1,sizeof(s1));
			}

		  f1.close();
		  break;

case 6:f1.open("stf1.dat",ios::in);
		 f2.open("stf2.dat",ios::out|ios::app);
		 f3.open ("stf3.dat",ios::out|ios::app);
		 cout<<"\nEnter Name of the Employee:\n";
			gets(str);
			i=0;
			f1.read((char*)&s1,sizeof(s1));
			while(f1)
			{
			n=s1.searchst(str);
			if(n==0)
			{i++;
			f3.write((char*)&s1,sizeof(s1));
			}
			if(n==1)
			{
			 f2.write((char*)&s1,sizeof(s1));
			}
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			f2.close();
			f3.close();
			remove("stf1.dat");
			rename("stf2.dat","stf1.dat");
			if(i==0)
			cout<<"\nEmployee does Not Work here";
			break;


case 7:
		 f1.open("stf3.dat",ios::in);
			f1.read((char*)&s1,sizeof(s1));
			cout<<"\nFired Employee Histiry";
			cout<<"\n-----------------------";
			cout<<"\nName\t"<<"\tAge\t"<<"\tJob\t"<<"\tSalary\t";

			while(f1)
			{
			s1.displays();
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			break;
case 8:f1.open("stf1.dat",ios::out|ios::app);
		 f2.open("stf3.dat",ios::in);
		 cout<<"\nEnter the Employee's Name:\n";
		 gets(str);
		 i=0;
		 while(f2)
		 {
		 n=s1.searchst(str);
		 if(n==0)
		 {i++;
		 f1.write((char*)&s1,sizeof(s1));
		 }
		 f2.read((char*)&s1,sizeof(s1));
		 }
		 if(i==0)
		 cout<<"\nName not found";
		 else
		 cout<<"\nEmployee rehired";
		 f1.close();
		 f2.close();
		 break;
case 9:  f1.open("stf1.dat",ios::in);
			f2.open("bks.dat",ios::out|ios::app);
			f1.read((char*)&s1,sizeof(s1));

			while(f1)
			{
			f2.write((char*)&s1,sizeof(s1));
			f1.read((char*)&s1,sizeof(s1));
			}
			f2.close();
			f1.close();
			cout<<"\nBackUp Created";
			break;

case 10: remove("stf1.dat");
			rename("bks.dat","stf1.dat");
			cout<<"\nBackup Restored";
							break;
case 11:

				clrscr();
							break;
default:
	cout<<"\nWrong Choice";

}
	cout<<"\nDo you wish to continue?";
	cin>>ch4;
}while(ch4=='y'||ch4=='Y');
}
if(ch==3)
{

	clrscr();
	exit(0);
}
else
{
	cout<<"\nWrong choice";

cout<<"\nDo u wish to select another access level";
cin>>ch1;

}
}while(ch1=='y'|ch1=='Y');

cout<<"\n\n\n\n";
clrscr();

}                                             //end of program
 

deviprasad742

Right off the assembly line
Re: Post ur C/C++ Programs Here

Code For Sudoku:

Here is the code to solve Sudoku which i wrote in C

It's bit-lenghty but it can solve all difficulty levels

here is the input format to be given at the command prompt
--->./a.out

11 5
12 4
14 6
15 1
19 8
23 1
25 9
29 4
31 1
33 5
37 7
40 9
44 2
47 6
49 8
51 3
55 2
61 7
66 5
68 3
69 6
-1

0-80 is the grid numbers

the format should be [grid number(0-80) [1-9]

input should end with -1;



Here is the source code:

Code:
#include<stdio.h>
#include<stdlib.h>

int check,zcount;


int update(int pos);
int re_update(int pos);


struct  str
{
int num;
int flag[10];
int group[20];
};



int count[81],once=0;

typedef struct str mynode;

mynode node[81];



///////////////////////////////////////////////




//////////////////////////////////////////////

int main()
{
int i,temp,temp_n[81],tcount=0,num,index;
int n[81];

for(i=0;i<81;i++)
n[i]=0;







printf("\n");



/*---------------------------Taking input------------------------------------*/



printf("\nEnter the index 0-80  and number  1-9\n");
printf("\nEnter -1  to  solve the puzzle \n");

while(1)
{

scanf("%d",&index);



if(index==-1)
break;

scanf("%d",&num);

 if(num>9||num<1||index>80||index<0)
{
printf("\n.......Invalid input.........\n");
continue;
}

else if(node[index].num!=0)
{
printf("\n.......Already filled........\n");
continue;
}

else
{
node[index].num=num;
update(index);
tcount++;
}



}

zcount=81-tcount;

printf("\n-------------------The number of filled places is %d------------------\n",tcount);







for(i=0;i<81;i++)
printf("%2d  ",count[i]);
printf("\n");






tcount=0;


printf("\n\n");

printf("\n\n");


for(i=0;i<81;i++)
{
printf("%2d  ",node[i].num);

if(node[i].num==0)
tcount++;

if((i+1)%3==0)
printf("    ");

if((i+1)%9==0)
printf("\n\n");

if((i+1)%27==0)
printf("\n");

}




printf("\n-------------------The number of unfilled places is %d------------------\n",tcount);





for(i=0;i<81;i++)
n[i]=node[i].num;



for(i=0;i<81;i++)
{
temp_n[i]=n[i];
temp=check_error(i,n);

if(temp==-1)
{
printf("\n\n");
printf("-------Puzzle cannot be solved -------- ");
printf("\n\n");
printf("-------Error at block %d -------- ",i);
printf("\n\n");
exit(0);
}

}




temp=0;

temp=sudoku();



if(temp==-1)
printf("\n Puzzle is not solved \n");



for(i=0;i<81;i++)
printf("%2d  ",count[i]);
printf("\n");




printf("\n\n");

tcount =0;
for(i=0;i<81;i++)
{
printf("%d  ",node[i].num);

if(node[i].num==0)
tcount++;

if((i+1)%3==0)
printf("    ");

if((i+1)%9==0)
printf("\n\n");

if((i+1)%27==0)
printf("\n");
 
}












}





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


int sudoku()
{
int i,j,k,error=0,numb=8,flag=0,s_error=0,n[81],temp=0 ;




while(zcount!=0)
{

flag=1;


for(i=0;i<81;i++)
{

if(count[i]==numb&&node[i].num==0)
{
flag=0; //indicating that  a node with required count is present in the loop;

for(j=1;j<10;j++)
if(node[i].flag[j]==0)
{
node[i].flag[j]=1;
node[i].num=j;
printf("\n<------Element %2d set to %d------->",i,j);


count[i]++;
zcount--;



error=update(i);

if(error==-1)
{
printf("\n---reupdating started");
re_update(i);
count[i]--;
zcount++;
node[i].flag[j]=0;
printf("\n---reupdating finished");
continue;
}

else
s_error=sudoku();

if(s_error==-1)
{
re_update(i);
count[i]--;
zcount++;
node[i].flag[j]=0;
continue;
}

//printf("\n----> zeroes-%2d",zcount);

printf("\n---Breaking");

break;
}
else
continue;

if(error==-1||s_error==-1)
return -1;

}

if(zcount==0)
break;

}



if(flag==1)
numb--;





}


/*
for(i=0;i<81;i++)
printf("%2d  ",count[i]);
printf("\n");
*/



if(once==1)
{

for(i=0;i<81;i++)
n[i]=node[i].num;


for(i=0;i<81;i++)
{
temp=check_error(i,n);

if(temp==-1)
{
printf("\n\n");
printf("-------Puzzle wrongly solved -------- ");
printf("\n\n");
printf("-------Error at block %d -------- ",i);
printf("\n\n");
exit(0);
}

}


exit(0);
}


printf("\n\n");

printf("\n\n");

for(i=0;i<81;i++)
{
printf("%2d  ",node[i].num);

if((i+1)%3==0)
printf("    ");

if((i+1)%9==0)
printf("\n\n");

if((i+1)%27==0)
printf("\n");
 
}

once=1;

return 0;
}













///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


int check_error(int pos,int *block)
{

int m,n,index,t_num,flag=0,t_index,i,j;

i=pos/9;
j=pos%9;
index=i*9+j;

if(block[index]!=0)
{
t_num=block[index];


for(m=0;m<9;m++)
{

if(m!=i)
{
t_index=m*9+j;
if(block[t_index]==t_num)
flag=1;
}

if(m!=j)
{
t_index=9*i+m;
if(block[t_index]==t_num)
flag=1;
}

if(flag==1)
{
//printf("--------->Break at %d---pos=%d<-----------\n",m,pos);
return -1;
}

// row and  column check completed;
}

/////////////1


for(m=i+1;m>=0;m++)
{

if(m%3==0)
break;

for(n=j+1;n>=0;n++)
{
if(n%3==0)
break;

t_index=9*m+n;

if(block[t_index]==t_num)
{
//printf("--------->Break at %d %d---pos=%d-------------->\n",m,n,pos);
return -1;
}

}
}


/////////2

for(m=i+1;m>=0;m++)
{

if(m%3==0)
break;

for(n=j-1;n>=0;n--)
{
if(n%3==2)
break;

t_index=9*m+n;

if(block[t_index]==t_num)
{
//printf("--------->Break at %d %d-------------->\n",m,n);
return -1;
}

}
}


///////////////3

for(m=i-1;m>=0;m--)
{

if(m%3==2)
break;

for(n=j-1;n>=0;n--)
{
if(n%3==2)
break;

t_index=9*m+n;

if(block[t_index]==t_num)
{
//printf("--------->Break at %d %d-------------->\n",m,n);
return -1;
}

}
}

//// 4

for(m=i-1;m>=0;m--)
{

if(m%3==2)
break;

for(n=j+1;n>=0;n++)
{
if(n%3==0)
break;

t_index=9*m+n;

if(block[t_index]==t_num)
{
//printf("--------->Break at %d %d-------------->\n",m,n);
return -1;
}

}
}





//end of num!=0 check;
}





return 0;

}






///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


int update(int pos)
{

int m,n,index,t_num,flag=0,t_index,i,j,l,error=0;

i=pos/9;
j=pos%9;
index=i*9+j;

if(node[index].num!=0)
{
t_num=node[index].num;


for(m=0;m<9;m++)
{



if(m!=i)
{
t_index=m*9+j;

if(node[t_index].flag[t_num]==0)
{
node[t_index].flag[t_num]=1;
count[t_index]++;

if(count[t_index]==9&&node[t_index].num==0)
error=-1;





for(l=0;l<20;l++)
if(node[index].group[l]==0)
{

if(t_index==0)
t_index=-1;

node[index].group[l]=t_index;
break;
}
else
continue;

}


}


if(m!=j)
{
t_index=9*i+m;


if(node[t_index].flag[t_num]==0)
{
node[t_index].flag[t_num]=1;
count[t_index]++;

if(count[t_index]==9&&node[t_index].num==0)
error=-1;


for(l=0;l<20;l++)
if(node[index].group[l]==0)
{
if(t_index==0)
t_index=-1;
node[index].group[l]=t_index;
break;
}
else
continue;

}



}

// row and  column check completed;
}

/////////////1


for(m=i+1;m>=0;m++)
{

if(m%3==0)
break;

for(n=j+1;n>=0;n++)
{
if(n%3==0)
break;

t_index=9*m+n;


if(node[t_index].flag[t_num]==0)
{
node[t_index].flag[t_num]=1;
count[t_index]++;

if(count[t_index]==9&&node[t_index].num==0)
error=-1;




for(l=0;l<20;l++)
if(node[index].group[l]==0)
{
if(t_index==0)
t_index=-1;
node[index].group[l]=t_index;
break;
}
else
continue;

}



}
}


/////////2

for(m=i+1;m>=0;m++)
{

if(m%3==0)
break;

for(n=j-1;n>=0;n--)
{
if(n%3==2)
break;

t_index=9*m+n;


if(node[t_index].flag[t_num]==0)
{
node[t_index].flag[t_num]=1;
count[t_index]++;

if(count[t_index]==9&&node[t_index].num==0)
error=-1;


for(l=0;l<20;l++)
if(node[index].group[l]==0)
{
if(t_index==0)
t_index=-1;
node[index].group[l]=t_index;
break;
}
else
continue;

}



}
}



///////////////3

for(m=i-1;m>=0;m--)
{

if(m%3==2)
break;

for(n=j-1;n>=0;n--)
{
if(n%3==2)
break;

t_index=9*m+n;

if(node[t_index].flag[t_num]==0)
{
node[t_index].flag[t_num]=1;
count[t_index]++;


if(count[t_index]==9&&node[t_index].num==0)
error=-1;

for(l=0;l<20;l++)
if(node[index].group[l]==0)
{
if(t_index==0)
t_index=-1;
node[index].group[l]=t_index;
break;
}
else
continue;

}




}
}

//// 4

for(m=i-1;m>=0;m--)
{

if(m%3==2)
break;

for(n=j+1;n>=0;n++)
{
if(n%3==0)
break;

t_index=9*m+n;


if(node[t_index].flag[t_num]==0)
{
node[t_index].flag[t_num]=1;
count[t_index]++;


if(count[t_index]==9&&node[t_index].num==0)
error=-1;


for(l=0;l<20;l++)
if(node[index].group[l]==0)
{
if(t_index==0)
t_index=-1;
node[index].group[l]=t_index;
break;
}
else
continue;

}



}
}





//end of num!=0 check;
}



if(error==-1)
printf("\nError at --%d \n",pos);

return error;

}







///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


int re_update(int pos)
{

int m,n,index,t_num,flag=0,t_index,i,j,l;

i=pos/9;
j=pos%9;
index=i*9+j;

if(node[index].num!=0)
{
t_num=node[index].num;
node[index].num=0;

for(l=0;l<20;l++)
{

if(node[index].group[l]==0)
break;

t_index=node[index].group[l];

if(t_index==-1)
t_index=0;

node[t_index].flag[t_num]=0;
count[t_index]--;
node[index].group[l]=0;

}






}







return 0;

}
 
Last edited by a moderator:

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

You could have cut the length of the code down to half if you removed all the groups of empty lines :)
 

deb_gopal

Right off the assembly line
Re: Post ur C/C++ Programs Here

can any body give the visual basic 6 code for popup date calendar to date field and saving & loading photo through picture box control to access database ?
pls help me
 

[xubz]

"The Cake is a Lie!!"
Re: Post ur C/C++ Programs Here

Heh! Made this as a challenge to a friend who started a debate about graphics.h.. Its a simple DOS Text-based alien shooter game.. The following code is released under Creative Commons Share Alike, Attribution License.

Compiles Obviously only on TC.. A Lame one.. I know :-\

Code:
/* DESTROY TEH ALIENS (c) [XUBZ] */
#include<stdio.h>
#include<conio.h>
#include<dos.h>

/* Total no of Shots to give for shooting down 10 Aliens */
#define NUMSHOTS 11

char alien[80];
int score;
int shots;
int lastflag = 0;
int alienpos = 3;
int aliensound = 100;

void drawmain(int pos)
{
	int i;
	clrscr();

	/* Draw the Ground */
	for(i = 1; i <= 80; i++) {
		gotoxy(i, 24);
		textcolor(GREEN);
		cprintf("_");
		gotoxy(i, 7);
		textcolor(BLUE);
		cprintf("_");
		gotoxy(i, 24);
	}

	/* Draw the Cannon based on Current Position */
	textcolor(RED);
	gotoxy(pos, 23);
	cprintf(" || ");
	textcolor(GREEN);
	gotoxy(pos, 24);
	cprintf("|__|");
	textcolor(BLUE);
	gotoxy(pos+1, 7); /* For Shot Marker on the Top */
	cprintf(".");

	/* Draw the 'Quit' and 'New Game' Messages */
	gotoxy(2, 2);
	textcolor(RED);
	cprintf("Press Q to Exit");
	gotoxy(2, 3);
	cprintf("Press N for New Game");

	/* Draw the Current Cannon Position */
	gotoxy(66, 2);
	textcolor(YELLOW);
	cprintf("Position: %d", pos);

	/* Draw the Score */
	gotoxy(66, 5);
	textcolor(BLUE);
	cprintf("Score: %d", score);

	/* Draw No. of Shots */
	gotoxy(66, 6);
	textcolor(RED);
	cprintf("Shots Left: %d", shots);

	gotoxy(2, 6);
	textcolor(YELLOW);
	cprintf("DESTROY TEH ALIENS(tm) v0.1 (C) [XUBZ]");

	/* Draw the Aliens */
	if (!lastflag) {
		alienpos = (alienpos == 3) ? 0 : alienpos;
		aliensound = (aliensound == 250) ? 100 : aliensound;
		gotoxy(1+(alienpos++), 10);
	} else {
		gotoxy(alienpos, 10);
	}

	for (i = 0; i < 80; i++) {
		textcolor(WHITE);
		cprintf("%c", alien[i]);
	}

	if (!lastflag) {
		gotoxy(80, 25);
		sound(aliensound);
		delay(50);
		aliensound += 50;
		nosound();
	}

	/* If Score is 10; Show 'You Won' and Play Music ^_^ */
	if (score == 10) {
		gotoxy(36, 15);
		textcolor(YELLOW);
		cprintf("YOU WON!");
		gotoxy(30, 16);
		cprintf("Press N for New Game");
		if (!lastflag) {
			sound(250);
			delay(100);
			sound(450);
			delay(100);
			sound(350);
			delay(100);
			sound(450);
			delay(100);
			sound(350);
			delay(100);
			nosound();
			lastflag = 1;
		}
	}

	/* If No Shots left and score is NOT 10; Show 'Game Over' and Play Music */
	if (shots == 0 && score != 10) {
		gotoxy(35, 15);
		textcolor(RED);
		cprintf("GAME OVER");
		gotoxy(30, 16);
		cprintf("Press N for New Game");
		if (!lastflag) {
			sound(250);
			delay(100);
			sound(350);
			delay(100);
			sound(450);
			delay(100);
			nosound();
			lastflag = 1;
		}
	}

	/* Move the Cursor to End of the Screen for reducing color corruption :-\ */
	textcolor(BLUE);
	gotoxy(80, 25);
}

void newgame()
{
	int i;
	for(i = 0; i < 80; i++)
		alien[i] = '\0';

	/* Alien Positions */
	alien[6] = '0';
	alien[13] = '8';
	alien[18] = '0';
	alien[25] = '0';
	alien[65] = '0';
	alien[32] = '8';
	alien[45] = '0';
	alien[50] = '8';
	alien[58] = '0';
	alien[73] = '0';

	/* Set/Reset the No. of Shots, Score and Flag */
	score = 0;
	shots = NUMSHOTS;
	lastflag = 0;
	alienpos = 3;
	aliensound = 100;
}

void main()
{
	char c;
	int i, curpos = 38;
	clrscr();

	/* Draw Title Screen */
	newgame();
	gotoxy(30, 10);
	textcolor(GREEN);
	cprintf("DESTROY TEH ALIENS(tm)");
	gotoxy(33, 12);
	textcolor(YELLOW);
	cprintf("Press N to Start!");
	gotoxy(80, 25);
	textcolor(BLUE);

	while(c != 'q' && c != 'Q') {
		c = getch();

		/* Move the Cannon; \K is ASCII for Left Key and \M for Right */
		if (c == '\K' || c == '\M') {
			if (c == '\K') {
				if (curpos >= 3)
					curpos--;
			} else if (c == '\M') {
				if (curpos <= 75)
					curpos++;
			}
			drawmain(curpos);
		}

		/* Shoot the Alien and Register the Shots/Score */
		if (c == ' ') {
			if (!lastflag) {
				sound(400);
				delay(100);
			}
			if (curpos >= 2 && curpos <= 76)
				if (shots > 0) {

					if (alien[curpos-(alienpos-1)] == '0' || alien[curpos-(alienpos-1)] == '8') {
						alien[curpos-(alienpos-1)] = '*';
						sound(600);
						delay(100);
						score++;
					}
					shots--;
				}
			nosound();
			drawmain(curpos);
		}

		/* Reset the Game */
		if (c == 'n' || c == 'N') {
			newgame();
			curpos = 38;
			drawmain(curpos);
		}
	}
}
 

hero_techno

Right off the assembly line
Re: Post ur C/C++ Programs Here

#include<fstream.h>
void main()
{hey can anyone send me or make a c++ project for me based on anything...but includes, deletion, insertion, modification, addition, editing....for my class 12 project..no need of graphics n 1 thing laso i need this based on data file handling and class;
}
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

I could help you do your class 12 project, but for a reasonable sum.

#include<fstream.h>
void main()
{
Is that okay with you or are you gonna learn more than #include(s) ?
}
 

legolas

Padawan
Re: Post ur C/C++ Programs Here

there are plenty of sites which offer you what you need which you can get on google, which spoil your academics. Its a project. This is the time for you to learn.
 

hero_techno

Right off the assembly line
Re: Post ur C/C++ Programs Here

i know!! i can make project myself...but prolem is that ...i don have any time to do that....
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Imagine that.

How did you reason out that we would have time for your academics, when you do not have it yourself?
 

Cool Joe

The Black Waltz
Re: Post ur C/C++ Programs Here

This is my program written in C. it does unit conversions.
Code:
#include<stdio.h>
#include<conio.h>
main()
{
int opt,con;
float in,cm,ina,cma,ft,m,ma,fta,m1,y,m1a,ya,km,mile,mile1,km1,nmile,metre;
float nmile1,metre1,usgal,usl,usgal1,usl1,ukl,ukgal,ukl1,ukgal1,gram,oz;
float oz1,gram1,kg,lbs,lbs1,kg1,kw,hp,kw1,hp1,df,dc,df1,dc1;
clrscr();

printf("------------------------------Converter by Shishir------------------------------\n");
printf("\n1.Conversions\n");
printf("\n2.About Converter\n");
printf("\n3.Exit\n");
printf("\nEnter your choice:");
scanf("%d",&opt);

if(opt==1)
{
clrscr();
printf("\n1.inch to centimetre  2.centimetre to inch\n");
printf("\n3.foot to metre       4.metre to foot\n");
printf("\n5.yard to metre       6.metre to yard\n");
printf("\n7.mile to kilometre   8.kilometre to mile\n");
printf("\n9.n mile to metre     10.metre to n mile\n");
printf("\n11.US gal to litre    12.litre to US gal\n");
printf("\n13.UK gal to litre    14.litre to UK gal\n");
printf("\n15.Oz to gram         16.gram to Oz\n");
printf("\n17.pound to Kg        18.Kg to pound\n");
printf("\n19.hp to kw           20.kw to hp\n");
printf("\nEnter your unit of conversion:");
scanf("%d",&con);

if(con==1)
{
clrscr();
printf("How many inches? :");
scanf("%f",&in);
cm=in*2.54;
printf("\n\nConversion is %f CM",cm);
}

else if(con==2)
{
clrscr();
printf("How many centimtres? :");
scanf("%f",&cma);
ina=cma/2.54;
printf("\n\nConversion is %f IN",ina);
}

else if(con==3)
{
clrscr();
printf("How many feet? :");
scanf("%f",&ft);
m=ft/3.280839895;
printf("\n\nConversion is %f M",m);
}
else if(con==4)
{
clrscr();
printf("How many metres? :");
scanf("%f",&ma);
fta=ma*3.280839895;
printf("\n\nConversion is %f FT",fta);
}

else if(con==5)
{
clrscr();
printf("How many yards? :");
scanf("%f",&y);
m1=y/1.093613298;
printf("\n\nConversion is %f M",m1);
}

else if(con==6)
{
clrscr();
printf("How many metres? :");
scanf("%f",&m1a);
ya=m1a*1.093613298;
printf("\n\nConversion is %f Y",ya);
}

else if(con==7)
{
clrscr();
printf("How many miles? :");
scanf("%f",&mile);
km=mile*1.609344;
printf("\n\nConversion is %f KM",km);
}

else if(con==8)
{
clrscr();
printf("How many KMs? :");
scanf("%f",&km1);
mile1=km1/1.609344;
printf("\n\nConversion is %f miles",mile1);
}

else if(con==9)
{
clrscr();
printf("How many nautical miles? :");
scanf("%f",&nmile);
metre=nmile*1852;
printf("\n\nConversion is %f M",metre);
}
else if(con==10)
{
clrscr();
printf("How many metres? :");
scanf("%f",&metre1);
nmile1=metre1/1852;
printf("\n\nConversion is %f N MILES",nmile1);
}
else if(con==11)
{
clrscr();
printf("How many US gallons? :");
scanf("%f",&usgal);
usl=usgal*3.785412;
printf("\n\nConversion is %f L",usl);
}

else if(con==12)
{
clrscr();
printf("How many litres? :");
scanf("%f",&usl1);
usgal1=usl1/3.785412;
printf("\n\nConversion is %f US GAL",usgal1);
}

else if(con==13)
{
clrscr();
printf("How many UK gallons? :");
scanf("%f",&ukgal);
ukl=ukgal*4.54609;
printf("\n\nConversion is %f L",ukl);
}

else if(con==14)
{
clrscr();
printf("How many litres? :");
scanf("%f",&ukl1);
ukgal1=ukl1/4.54609;
printf("\n\nConversion is %f UK GAL",ukgal1);
}

else if(con==15)
{
clrscr();
printf("How many oz? :");
scanf("%f",&oz);
gram=oz*28.34952;
printf("\n\nConversion is %f G",gram);
}

else if(con==16)
{
clrscr();
printf("How many grams? :");
scanf("%f",&gram1);
oz1=gram1/28.34952;
printf("\n\nConversion is %f OZ",oz1);
}

else if(con==17)
{
clrscr();
printf("How many lbs? :");
scanf("%f",&lbs);
kg=lbs/2.204622476;
printf("\n\nConversion is %f KG",kg);
}

else if(con==18)
{
clrscr();
printf("How many kgs? :");
scanf("%f",&kg1);
lbs1=kg1*2.204622476;
printf("\n\nConversion is %f LBS",lbs1);
}

else if(con==19)
{
clrscr();
printf("How much hp? :");
scanf("%f",&hp);
kw=hp/1.341021859;
printf("\n\nConversion is %f KWs",kw);
}

else if(con==20)
{
clrscr();
printf("How many KWs? :");
scanf("%f",&kw1);
hp1=kw1*1.341021859;
printf("\n\nConversion is %f HP",hp1);
}

}

else if(opt==2)
{
clrscr();
printf("\nThis is a freeware by Shishir Upadhya.");
}

else if(opt==3)
{
printf("\nPress any key to exit...");
}

getch();
}

plz tell me wat u think abt it.

 
Last edited by a moderator:

mehulved

18 Till I Die............
Re: Post ur C/C++ Programs Here

beta testing's program working with gcc - *blog.mehulved.com/conversion-0.1.tar.bz2
Also, added a while loop so that it runs till exited and cleaned up a bit of formatting.
 
Status
Not open for further replies.
Top Bottom