#include <iostream.h>
int main()
{
int x[2][2][2], y[2]={1,1};
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
{
cout<<"Enter: "<<i<<"\t"<<j<<"\t"<<k<<"\n";
cin>>x[i][j][k];
}
for(int c=0;c<2;c++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
y[c]*=x[c][j][k];
cout<<"Result:"<<"\n"<<y[0]<<"\t"<<y[1];
return 0;
}
//end
#include <iostream>
#include <string>
using namespace std;
void main()
{
char string[] = "The String to End All Strings!";
cout<<"Mixed:\n"<<string<<endl;
cout<<"Uper:\n"<<strupr(string)<<endl;
char* lwr_str=strlwr(string);
cout<<"Lower:\n"<<lwr_str<<endl;
}
//end
#include <iostream>
#include <string>
using namespace std;
void main(void)
{
char ch='r';
char string[] =
"The quick brown dog jumps over the lazy fox";
char fmt1[] =
" 1 2 3 4 5";
char fmt2[] =
"12345678901234567890123456789012345678901234567890";
char* pdest;
int result;
cout<<"String to be searched: \n\t\t"<<string<<"\n";
cout<<"\t\t"<<fmt1<<"\n\t\t"<<fmt2<<"\n\n";
cout<<"Search char:\t"<<ch<<"\n";
/* Search forward. */
pdest=strchr(string, ch);
result=pdest - string + 1;
if( pdest != NULL )
cout<<"Result:\tfirst "<<ch
<<" found at position "<<result<<"\n\n";
else
cout<<"Result:\t"<<ch<<" not found\n";
/* Search backward. */
pdest=strrchr(string, ch);
result=pdest - string + 1;
if( pdest != NULL )
cout<<"Result:\tfirst "<<ch
<<" found at position "<<result<<"\n\n";
else
cout<<"Result:\t"<<ch<<" not found\n";
}
//end
#include <iostream>
#include <string>
using namespace std ;
int main()
{
char str [16] = "how long am I ?";
int len ;
len = strlen(str) ;
cout<<str<<" is "<<len<<" characters long\n";
return 0;
}
//end
int strlen(const char *s)
{
for(int i=0;s[i];++i);
return i;
}
char *strrchr(const char *s,int c)
{
long i;
for(i=strlen(s)-1;i>=0 && s[i]!=(char)c;i--);
if(i<0)
return NULL;
else
return (char *)&s[i];
}
//end
char *strncpy(char *s,const char *t,unsigned n)
{
for(unsigned i=0;i<n && t[i]!='\0';i++)
s[i]=t[i];
for(;i<n;i++)
s[i]='\0';
return s;
}
//end
char *strncpy(char *s,const char *t,unsigned n)
{
char *ts=s;
for(unsigned i=0;i<n && *t!='\0';i++,s++,t++)
*s=*t;
for(;i<n;i++,s++)
*s='\0';
return ts;
}
//end
char *strcpy(char *s,const char *t)
{
int i=0;
while((s[i]=t[i])!='\0')
i++;
return s;
}
//end
char *strcpy(char *s,const char *t)
{
char *ts;
ts=s;
while((*s=*t)!='\0')
{
s++;
t++;
}
return ts;
}
//end
int strlen(const char *s)
{
for(int i=0;s;++i);
return i;
}
char *strchr(const char *s,int c)
{
unsigned i;
for(i=0;i<strlen(s) && s!=(char)c;++i);
if(i==strlen(s))
return NULL;
else
return (char *)&s;
}
//end
#include <iostream.h>
#include <conio.h>
int Matrix(int** matrix,int size)
{
int down=0,up=0;
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(j>i && matrix[i][j] != 0)
down=2;
if(i>j && matrix[i][j] != 0)
up=1;
}
}
return down+up;
}
int main()
{
int size=0;
cout<<"Enter size of matrix(number of rows and columns):";
cin>>size;
cout<<endl;
int **matrix=new int*[size];
for(int i=0;i<size;i++)
matrix[i]=new int[size];
int row=1;
while(row<=size)
{
cout<<"Enter numbers for row "<<row<<":";
for(int i=0;i<size;i++)
{
cin>>matrix[row-1][i];
}
row++;
}
for(i=0;i<size;i++)
{
for(int j=0;j<size;j++)
cout<<matrix[i][j]<<" ";
cout<<endl;
}
cout<<endl<<endl;
int ud=Matrix(matrix,size);
if(ud==3)
{
cout<<"Hich kodum"<<endl;
}
else if(ud==2)
{
cout<<"Bala mosallasi"<<endl;
}
else if(ud==1)
{
cout<<"Paein mosallasi"<<endl;
}
else if(ud==0)
{
cout<<"Har do"<<endl;
}
cout<<"Press any key to quit...";
getch();
return 0;
}
//end
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
void main()
{
int x[20], n, scr=0;
char ch;
cout<<"Enter the number of characters:"<<endl;
cin>>n;
for(int i=0;i<n;i++)
x[i]=(97+random(26));
clrscr();
cout<<"Enter your guess:"<<endl;
for(int c=0;c<n;c++)
cout<<"-";
gotoxy(1,2);
for(i=0;i<n;i++)
{
ch=getche();
if(x[i]!=ch)
scr--;
else
scr++;
}
cout<<"\nCorrect Characters: ";
for(i=0;i<n;i++)
{
ch=x[i];
cout<<ch;
}
cout<<"\nYour score: "<<scr;
}
//end
#include <iostream.h>
#include <string.h>
void main(void)
{
char string1[]="The quick brown dog jumps over the lazy fox";
char string2[]="The QUICK brown fox jumps over the lazy dog";
char tmp[20];
int result;
cout<<"Compare strings:\n\t\tString1= "<<string1
<<"\n\t\tString2= "<<string2<<"\n\n";
cout<<"Function:\tstrncmp(first 10 characters only)\n";
result = strncmp( string1, string2 , 10 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
cout<<"Result:\t\tString 1 is "<<tmp<<" string 2\n\n";
cout<<"Function:\t_strnicmp (first 10 characters only)";
result = strnicmp( string1, string2, 10 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
cout<<"\nResult:\t\tString 1 is "<<tmp<<" string 2\n\n";
}
//end
#include <iostream.h>
#include <cstring.h>
int main(){
char str[ ] = "cats are nice usually.";
cout<<"before operating :\n"<<str;
strncpy(str,"dogs",4);
strncpy(str+9,"mean",4);
cout<<"\nafter operating :\n"<<str<<endl;
return 0 ;
}
//end
//This program shows concatenation of string object.
#include <iostream.h>
#include <cstring.h>
int main()
{
char S1[ ]="computer";
string S2=S1;
cout<<S2<<endl;
strcpy(S1," science");
S2=S2+S1;
cout<<S2<<endl;
return 0;
}
//end
//This program copies one string to another.
#include <iostream.h>
#include <conio.h>
int main()
{
char s1[2000],s2[2000];
cout<<"Please enter a sentence:\n";
cin.get(s1,100,'.');
for(int i=0; i<2000 && s1[i]!='\0'; i++)
s2[i]=s1[i];
s2[i]='\0';
clrscr();
cout<<"You entered :\n";
cout<<s2<<endl;
return 0;
}
//end
//This program calculates the product of 2 matrix.
#include <iostream.h>
#include <vector.h>
#include <conio.h>
int main()
{
int m,n,p;
cout<<"Enter size of tow integer matrix to get the product of them.\n";
cout<<"Enter size of first matrix A(m*n).\n";
cout<<"Enter m = ";
cin>>m;
cout<<"Enter n = ";
cin>>n;
vector <vector <int> > A(m, vector <int> (n,0));
cout<<"\nEnter size of second matrix B("
<<n<<"*p) .\n";
cout<<"Enter p = ";
cin>>p;
vector <vector <int> > B(n, vector <int> (p,0));
clrscr();
cout<<"Enter Matrix A members:\n";
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{
cout<<"Enter A["<<(i+1)<<"]["<<(j+1)<<"] =";
cin>>A[i][j];
}
cout<<"\nEnter Matrix B members:\n";
for(i=0;i<n;i++)
for(int j=0;j<p;j++)
{
cout<<"Enter B["<<(i+1)<<"]["<<(j+1)<<"] =";
cin>>B[i][j];
}
vector <vector <int> > C(m, vector <int> (p,0));
for(i=0;i<m;i++)
for(int k=0;k<p;k++)
for(int j=0,sum=0;j<n;j++)
C[i][k]+=A[i][j]*B[j][k];
clrscr();
for(i=0;i<m;i++)
{
for(int j=0;j<p;j++)
cout<<C[i][j]<<"\t";
cout<<endl;
}
return 0;
}
//end
//This program gets the sum of two huge integer numbers.
#include <iostream.h>
#include <conio.h>
#include <vector.h>
int main()
{
vector <char> num1,num2,result;
cout<<"Enter tow huge integer numbers to get the sum of them.\n";
cout<<"Enter number one and press enter key.\n\n";
char ch;
while((ch=getch())!=13)
{
if(ch>='0'&& ch<='9')
{
cout.put(ch);
ch-=48;
num1.push_back(ch);
}
}
cout<<"\n+"<<endl;
while((ch=getch())!=13)
{
if(ch>='0'&& ch<='9')
{
cout.put(ch);
ch-=48;
num2.push_back(ch);
}
}
cout<<"\n="<<endl;
int min_size;
min_size = num1.size() < num2.size() ?
num1.size() : num2.size();
bool carry=0;
while(min_size>0)
{
if(num1.back()+num2.back()+carry<10)
{
result.push_back(num1.back()+num2.back()+carry);
num1.pop_back();
num2.pop_back();
carry=0;
}
else
{
result.push_back((num1.back()+num2.back()+carry)%10);
num1.pop_back();
num2.pop_back();
carry=1;
}
min_size--;
}
while(num1.size()!=0)
{
if(num1.back()+carry<10)
{
result.push_back(num1.back()+carry);
num1.pop_back();
carry=0;
}
else
{
result.push_back((num1.back()+carry)%10);
num1.pop_back();
carry=1;
}
}
while(num2.size()!=0)
{
if(num2.back()+carry<10)
{
result.push_back(num2.back()+carry);
num2.pop_back();
carry=0;
}
else
{
result.push_back((num2.back()+carry)%10);
num2.pop_back();
carry=1;
}
}
if(carry==1)
result.push_back(1);
while(result.size()>0)
{
cout.put(result.back()+48);
result.pop_back();
}
cout<<endl;
return 0;
}
//end
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
int main()
{
int score[10][5]={0};
int lesson_sum[4]={0};
for(int i=0;i<3;i++)
{
for(int j=0;j<5;j++)
{
if(j==0)
{
cout<<"Please enter student number = ";
cin>>score[i][0];
}
else
{
cout<<"Enter score number "<<j<<" = ";
cin>>score[i][j];
lesson_sum[j-1]+=score[i][j];
}
}
clrscr();
}
clrscr();
for(i=0;i<10;i++)
{
float sum=0;
for(int j=1;j<5;j++)
sum+=score[i][j];
cout<<setw(2)<<(i+1)<<"-Averag of student "
<<setw(10)<<score[i][0]
<<" = "<<(sum/4)<<endl;
}
for(i=0;i<4;i++)
cout<<"\nAverage of lesson "<<(i+1)
<<" = "<<((float)lesson_sum[i]/10);
cout<<endl;
return 0;
}
//end
gotoxy(int x, int y);
//end
gotoxy(5, 10);
//end
#include <iostream>
#include <windows.h>
using namespace std;
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
cout.flush();
dwCursorPosition.X=x;
dwCursorPosition.Y=y;
hConsoleOutput=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput, dwCursorPosition);
}
void clrscr()
{
system("cls");
}
//end
#include <iostream.h>
#include <conio.h>
int main()
{
short month, day, total_days;
int day_per_month[12]={31,31,31,31,31,31,
30,30,30,30,30,29};
cout<<"Enter month (1 to 12) : ";
cin>>month;
if(month<1 || month>12)
{
cout<<"Wrong input! Press any key to end.\n";
getch();
return 0;
}
cout<<"Enter day (1 to 31) : ";
cin>>day;
total_days=day;
for(int i=0;i<month-1;i++)
total_days+=day_per_month[i];
cout<<"Total days from start of year is:"
<<total_days<<endl;
return 0;
}
//end
Thread starter | عنوان | تالار | پاسخ ها | تاریخ |
---|---|---|---|---|
A | لینک سورس بازی پک من به زبان سی پلاس پلاس | C++ , C | 0 | |
م | سورس برنامه فروشنده دوره گرد به زبان c++ | C++ , C | 2 | |
طریقه add کردن تعدادی فایل و یا فولدر به سورس پروژه ؟؟ | C++ , C | 1 | ||
سورس بازی پانگ به زبان c++ | C++ , C | 0 | ||
سورس برنامه نت پد در زبان c++ | C++ , C | 0 |