با سلام
این برنامه ای که برای شما قرار دادم تبدیل مبنای اعداد به یکدیگر است.
به این صورت که یک عدد رو از شما دریافت کرده و مبنای اون رو می پرسه و در مرحله آخر مبنای مورد نظر را پرسیده و عدد را به آن مبنا تبدیل می کند.
mabna1.rar
با سلام
این برنامه ای که برای شما قرار دادم تبدیل مبنای اعداد به یکدیگر است.
به این صورت که یک عدد رو از شما دریافت کرده و مبنای اون رو می پرسه و در مرحله آخر مبنای مورد نظر را پرسیده و عدد را به آن مبنا تبدیل می کند.
mabna1.rar
با سلام.من تازه در این انجمن عضو شدم.تجربه زیادی در برنامه نویسی ندارم ولی انگیزم برای یادگیری زیاده. اینم اولین برنامه ای که خودم نوشتم.
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int coin[8];
printf("please enter weight coins:\n");
for(int i=0;i<8;i++)
{
zokaeehamid@fastmail.fm Page 5
printf("coin[%d]=",i);
scanf("%d",&coin[i]);
}
printf("press key...\n");
getch();
if(coin[0]+coin[1]!=coin[2]+coin[3])//1
if(coin[0]==coin[2])//2
if(coin[1]==coin[2])//3
printf("coin[3]=%d",coin[3]);
else
printf("coin[1]=%d",coin[1]);
else
if(coin[0]==coin[3])
printf("coin[2]=%d",coin[2]);
else
printf("coin[0]=%d",coin[0]);
else
if(coin[4]==coin[6])
if(coin[5]==coin[6])
printf("coin[7]=%d",coin[7]);
else
printf("coin[5]=%d",coin[5]);
else
if(coin[4]==coin[7])
printf("coin[6]=%d",coin[6]);
else
printf("coin[4]=%d",coin[4]);
getch();
}
سلام
برنامه گرفتن اطلاعات دانشجو با استفاده از لیست پیوندی :
(Add
Del
Show
Count)
http://www.4shared.com/rar/sh-yVU8A/Link_List_2.html
این کد برای حل 2 معادله 2 مجهول.
توضیح این که:
ax+by=c
dx+ey=f
شما به ترتیب در سطر اول آ و ب و ث و در خط دوم دی و ای و اف رو وارد میکنید.
جوابی که بهتون نشون میده به ترتیب x و y هستن.
#include <iostream>
using namespace std;
double calculate_determinant(double a, double b, double c, double d);
int main(){
double a[2], b[2], c[2], x[2];// a va b zarayebe majhoolat hastand. c adade sabet. va x ham javabe moadelat.
for (int i=0; i<2; i++){
cout<<"Zarayebe moadeleye "<<i+1<<" va pasokhe an ra be tartib vared konid:";
cin>>a[i]>>b[i]>>c[i];
}
// Halle moadele be raveshe keramer.
double determinant_of_makhraj;// chon baraye hameye x[i] ha sabete, dg array nemigiram.
double determinant_of_soorat[2];// chon baraye har x[i] i in meghdar fargh darad.
determinant_of_makhraj=calculate_determinant(a[0], b[0], a[1], b[1]);
determinant_of_soorat[0]=calculate_determinant(c[0], b[0], c[1], b[1]);
determinant_of_soorat[1]=calculate_determinant(a[0], c[0], a[1], c[1]);
for (int i=0; i<2; i++){
x[i]=determinant_of_soorat[i]/determinant_of_makhraj;
}
for (int i=0; i<2; i++){
cout<<"x["<<i<<"]="<<x[i]<<endl;
}
cout<<endl;
return 0;
}
double calculate_determinant(double a, double b, double c, double d) {
return (a*d)-(b*c);
}
این هم یه class هست برای threading خوبیش اینه که در هر ورژن از ویندوز کار میکنه
Threading.zip
این کد یک منوی گرافیکی ادیتور فایل به صورت گرافیکی است که اولش با یک دمو شروع میشه
Download
کد تشخیص اینکه یک نقطه داخل یک مثلث یا یک چند ضلعی محدب، هست یا نه :
#ifndef SELRCT2D_NGOB_DEFINED
#define SELRCT2D_NGOB_DEFINED
#include <cmath>
using namespace std;
typedef struct TVec2D
{
public:
TVec2D() {};
TVec2D(const float x_, const float y_)
{
x = x_;
y = y_;
};
void SetVal(const float x_, const float y_)
{
x = x_;
y = y_;
};
void SetNormalVal(const float x_, const float y_)
{
float l = sqrtf(x_ * x_ + y_ * y_);
x = x_ / l;
y = y_ / l;
};
void Normalize()
{
float l = sqrtf(x * x + y * y);
x /= l;
y /= l;
};
void NormalBetween2Point(const TVec2D from_vec, const TVec2D to_vec)
{
x = to_vec.x - from_vec.x;
y = to_vec.y - from_vec.y;
float l = sqrtf(x * x + y * y);
x /= l;
y /= l;
};
float x, y;
} *PVec2D;
float V2DDot(const TVec2D v1, const TVec2D v2)
{
return (v1.x * v2.x + v1.y * v2.y);
};
bool V2DIsInTriangle(const TVec2D V, const TVec2D * aV)
{
TVec2D v0, v1, v2, v3;
v1.SetNormalVal(aV[2].x - aV[0].x,aV[2].y - aV[0].y);
v2.SetNormalVal(aV[1].x - aV[0].x,aV[1].y - aV[0].y);
v3.SetNormalVal(V.x - aV[0].x,V.y - aV[0].y);
if (V2DDot(v1,v2) > V2DDot(v1,v3))
{
return false;
}
else
{
v0 = v2;
v1.SetVal(-v1.x,-v1.y);
v2.SetNormalVal(aV[1].x - aV[2].x,aV[1].y - aV[2].y);
v3.SetNormalVal(V.x - aV[2].x,V.y - aV[2].y);
if (V2DDot(v1,v2) > V2DDot(v1,v3))
{
return false;
}
else
{
v2.SetNormalVal(-v1.x,-v1.y);
v3.SetNormalVal(V.x - aV[0].x,V.y - aV[0].y);
v1 = v0;
return (V2DDot(v1,v2) < V2DDot(v1,v3));
};
};
};
int FloorBy(const int x, const int LoopValue)
{
return (x % LoopValue);
};
bool V2DIsInNGon(const TVec2D V, const TVec2D * aV, const int edgeCount)
{
if (edgeCount < 3)
{
return false;
};
TVec2D v0, v1, v2, v3;
for (int i = 0; i < edgeCount; i++)
{
v0.NormalBetween2Point(V, aV[FloorBy(i + 1, edgeCount)]);
v1.NormalBetween2Point(aV[FloorBy(i, edgeCount)], aV[FloorBy(i + 1, edgeCount)]);
v2.NormalBetween2Point(aV[FloorBy(i + 2, edgeCount)], aV[FloorBy(i + 1, edgeCount)]);
if (V2DDot(v2, v1) > V2DDot(v0, v1))
{
return false;
}
}
return true;
};
#endif
این فایل هدر رو به برنامه اضافه کنید و مثلث یا چند ضلعی تون رو به شکل آرایه ای از نقاط (رئوس چند ضلعی) بسازید یعنی آرایه ای از TVec2D بعد با استفاده از توابع V2DIsInTriangle برای مثلث و V2DIsInNGon برای بیشتر از سه ضلعی میتونید تشخیص بدید که نقطه داخل شکل هست یا نه.
سعی کنید ضلع رو بزرگتر از 26 انتخاب نکنید:
#include<iostream.h>
void main () {
int x;
cout << "size azla ra vared konid : ";
cin >> x;
for (int j=0 ; j<x ; j++) {
for (int i= 1 ; i < (x-j) ; i++)
cout << " ";
for (int k=0 ; k<j+i ;k++)
cout << "* ";
cout << endl;
}
}
رسم مستطیل یا مربع تو خالی در C++ :
#include<iostream.h>
void main () {
int tool,arz;
cout << "tool mostatil ra vared konid : " << endl;
cin >> tool;
cout << "\narze mostatil ra vared konid : " << endl;
cin >> arz;
for (int i=0 ; i < tool ; i++)
cout << "* ";
cout << endl;
for (int j=0 ; j <arz-2 ; j++ ) {
cout << "* ";
for(int k =0 ; k < tool-2 ; k++)
cout << " ";
cout << "* ";
cout << endl;
}
for (int c=0 ; c < tool ; C++)
cout << "* ";
}
سلام دوستان یه برنامه نوشتم که معادله زیر رو حل میکنه ، نظرتون برام خیلی مهمه....
تشکر
//aidinMC Program
#include <iostream.h>
void main () {
int tavan=3,tedad,temp,tempx,tempy;
long int x,y,faktor;
double natije , natijeFaktor=0;
cout << "Lotfan tedad donbale ra varedkonid : ";
cin >> tedad ;
while (tedad > 7) {
cout << endl;
cout <<"DORE bayad kochaktar az 8 bashad!"<<endl;
cin >> tedad ;
}
cout << "X ra vared konid : ";
cin >> x;
while (x>5) {
cout << endl;
cout <<"X bayad kochaktar az 5 bashad!"<<endl;
cin >> x ;
}
natije=x;
tempy=y=-x;
tempx=x;
cout << "---------*****----------"<<endl;
cout <<" X = " << x<<endl;
cout << "---------*****----------"<<endl;
while ( tedad > 0 ) {
faktor = temp = tavan;
for (int i=1 ; i< tavan ; i++)
y=y*x;
cout << " x^"<<tavan<<" = "<< y << endl;
for (int j=1 ; j<tavan ; j++)
faktor *=(temp-j);
cout << " " << tavan << " Faktoriel = " << faktor<<endl;
natijeFaktor += (double)(faktor);
cout << " (" << y << "/" << natijeFaktor << ") = " << (y/natijeFaktor) <<endl;
natije += (y/natijeFaktor);
natijeFaktor = 0;
if (tempy > 0)
y=x=tempy=tempx* -1;
else if (tempy < 0)
y=x=tempy=tempx;
tavan+=2;
tedad--;
cout << "---------*****----------"<<endl;
}
cout << " natije Kol = "<< natije << endl;
}
البته مقدار x و دنباله محدود شده.....
برنامه دریافت 20 درس از ۱۱ دانشجو و ذخیره - ویرایش - حذف و نمایش اونها
با کامپایلر gcc و minGW سازگار هستش
#include <iostream>
#include <cstdlib>
//#include <conio.h>
using namespace std;
void mainMenu();
void showData(int index,int showScores);
long getID(char *str);
int searchID(long goal);
void secondMenu();
void sortByID();
void sortByAverage();
void sortByTops();
void sortByFamily();
void storeStd(int seek);
void clrscr();
int std_count = 0, choice = 1;
long goal = 0;
struct student
{
long ID;
char name[10], family[15], tel[12];
float sum;
struct book
{
char name[15];
float score;
int multiple;
}books[20];
}students[11], reset_std, second_std;
int main (int argc, char *argv[])
{
mainMenu();
return 0;
}
void mainMenu()
{
cout << "\n [1]- Create a new student" << "\n [2]- Edit student" << "\n [3]- Delete student" << "\n [4]- Show student" << "\n [5]- Quit" << "\n" ;
cout << "\n Choose a number between 1 to 5 : ";
cin >> choice;
switch (choice)
{
case 1:
{
storeStd(std_count);
mainMenu();
break;
}
case 2:
{
clrscr();
int index = searchID(getID("Enter the ID to EDIT : "));
if (index != -1)
{
cout << "Student Found\n";
showData(index,1);
storeStd(index);
}
else
cout << "Student Not Found\n";
mainMenu();
break;
}
case 3:
{
clrscr();
int index = searchID(getID("Enter the student`s NAME to DELETE : "));
if (index != -1)
{
students[index] = reset_std;
cout << "Student deleted successfully";
}
else
cout << "Student Not Found\n";
mainMenu();
break;
}
case 4:
{
clrscr();
secondMenu();
break;
}
case 5: exit(0);
default:
{
mainMenu();
break;
}
}
}
void showData(int index,int showScores)
{
cout << "\n ID : " << students[index].ID;
cout << "\n Name : " << students[index].name;
cout << "\n Family : " << students[index].family;
cout << "\n ";
if (students[index].tel[0] == '0' && students[index].tel[1] == '9')
cout << "Mobile : ";
else
cout << "Tel number: 0831-";
cout << students[index].tel;
cout << "\n Average : " << students[index].sum;
cout << "\n";
if (showScores == 1)
{
for(int i = 0; i <= 19; i++)
{
cout << "\n Book : " << students[index].books[i].name;
cout << "\n Grade :" << students[index].books[i].score;
cout << "\n Rate : " << students[index].books[i].multiple << "\n";
}
}
}
void sortByID()
{
for (int i = 0; i <=10; i++)
{
for (int j = i; j <= 10; j++)
{
if(students[i].ID > students[j].ID)
{
second_std = students[i];
students[i] = students[j];
students[j] = second_std;
}
}
showData(i,0);
}
}
void sortByAverage()
{
for (int i = 0; i <=10; i++)
{
for (int j = i; j <= 10; j++)
{
if(students[i].sum < students[j].sum)
{
second_std = students[i];
students[i] = students[j];
students[j] = second_std;
}
}
showData(i,0);
}
}
void sortByFamily()
{
for (int i = 0; i <=10; i++)
{
for (int j = i; j <= 10; j++)
{
if(students[i].family[0] > students[j].family[0])
{
second_std = students[i];
students[i] = students[j];
students[j] = second_std;
}
}
showData(i,0);
}
}
void sortByTops()
{
for (int i = 0; i <=10; i++)
{
for (int j = i; j <= 10; j++)
{
if(students[i].sum < students[j].sum)
{
second_std = students[i];
students[i] = students[j];
students[j] = second_std;
}
}
}
showData(0,0);
showData(1,0);
showData(2,0);
}
long getID(char *str)
{
int id;
cout << "\n " << str;
cin >> id;
return id;
}
int searchID(long goal)
{
for(int i=0; i <= 10; i++)
{
if (students[i].ID == goal)
{
return i;
}
}
return -1;
}
void secondMenu()
{
cout << "\n [1]- Show the list sorted by Family" << "\n [2]- Show the list sorted by ID" << "\n [3]- Show the list sorted by Grade" << "\n [4]- Show 3 best students" << "\n [5]- Exit" << "\n" ;
cout << "\n Choose a number between 1 to 5 : ";
cin >> choice;
switch (choice)
{
case 1:
{
sortByFamily();
secondMenu();
break;
}
case 2:
{
sortByID();
secondMenu();
break;
}
case 3:
{
clrscr();
sortByAverage();
secondMenu();
break;
}
case 4:
{
sortByTops();
secondMenu();
break;
}
case 5:
{
mainMenu();
break;
}
default:
{
clrscr();
secondMenu();
break;
}
}
}
void storeStd(int seek)
{
float x = 0;
long multiple = 0;
clrscr();
cout << " Enter ID : ";
cin >> students[seek].ID;
cout << "\t Enter Name : ";
cin >> students[seek].name;
cout << "\t Enter Family : ";
cin >> students[seek].family;
cout << "\t Enter Tel : ";
cin >> students[seek].tel;
for(int i = 0; i <= 19; i++)
{
cout << "\n Enter the Book`s Name : ";
cin >> students[seek].books[i].name;
cout << "\t Enter Grade : ";
cin >> students[seek].books[i].score;
cout << "\t Enter Rate : ";
cin >> students[seek].books[i].multiple;
multiple += students[seek].books[i].multiple;
x += (students[seek].books[i].score * students[seek].books[i].multiple);
}
students[seek].sum = x / multiple;
if (seek >= std_count)
std_count ++;
}
void clrscr()
{
for (int i = 0; i < 60; i++)
cout << endl;
}
دوست من پسوند فایل هرچیزی میتونه باشه. نوع دخیره کردن اصلاعات تو فایل شما از نوع باینری میباشد واسه همین اصلاعات به این شکل نمایش داده میشه
HASH SORT
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <fstream.h>
#include <stdlib.h>
struct Student{
char del;
char edit;
char name[20];
char family[30];
long id;
};
struct fhash{
char family[30];
long id;
};
struct idhash{
long id;
long adrs;
};
int GetRecordCount(void){
long pos;
int result;
fstream file;
file.open("student.txt",ios::in|ios::binary);
file.seekg(0,ios::end);
pos=file.tellg();
result=pos/sizeof(Student);
file.close();
return result;
}
int ExistID(int index,Student* st){
if(index==-1)
return 0;
idhash hash;
Student st_temp;
int result;
long pos=index*sizeof(hash);
fstream file,idhfile;
idhfile.open("idhash.txt",ios::in|ios::binary);
idhfile.seekg(pos,ios::beg);
idhfile.read((char*)&hash,sizeof(hash));
idhfile.close();
file.open("student.txt",ios::in|ios::binary);
file.seekg(hash.adrs,ios::beg);
file.read((char*)&st_temp,sizeof(st_temp));
file.close();
if(st_temp.del=='0')
result=1;
else
result=0;
*st=st_temp;
return result;
}
void IDInFile(int index,long* id){
idhash hash;
long pos=index*sizeof(hash);
fstream idhfile;
idhfile.open("idhash.txt",ios::in|ios::binary);
idhfile.seekg(pos,ios::beg);
idhfile.read((char*)&hash,sizeof(hash));
idhfile.close();
*id=hash.id;
}
int BinarySearchID(long value,int low,int high){
int mid,result;
long x;
if(high<low)
result=-1;
else{
mid=low+((high-low)/2);
IDInFile(mid,&x);
if(x>value)
result=BinarySearchID(value,low,mid-1);
else if(x<value)
result=BinarySearchID(value,mid+1,high);
else // if x=value
result=mid;
}
return result;
}
void FamilyInFile(int index,char* str){
fhash hash;
long pos=index*sizeof(hash);
fstream fhfile;
fhfile.open("fhash.txt",ios::in|ios::binary);
fhfile.seekg(pos,ios::beg);
fhfile.read((char*)&hash,sizeof(hash));
fhfile.close();
strcpy(str,hash.family);
}
int BinarySearchFamily(char* value,int low,int high){
int mid,result;
char x[30]={"0"};
if(high<low)
result=-1;
else{
mid=low+((high-low)/2);
FamilyInFile(mid,x);
if(strcmp(x,value)>0) // x>value
result=BinarySearchFamily(value,low,mid-1);
else if(strcmp(x,value)<0) // x<value
result=BinarySearchFamily(value,mid+1,high);
else // if x=value
result=mid;
}
return result;
}
void Insert(Student st,int low,int high){
int mid,i,l,h,test;
char x1[30]={"0"};
long x2;
fstream file,fhfile,idhfile;
fhash fh,fhtemp;
idhash idh,idhtemp;
file.open("student.txt",ios::app |ios::binary);
file.seekg(0,ios::end);
idh.id=st.id;
idh.adrs=file.tellg();
fh.id=st.id;
strcpy(fh.family,st.family);
file.write((char*)&st,sizeof(st));
file.close();
l=low;
h=high;
if(high==-1){
fhfile.open("fhash.txt",ios::app|ios::binary);
fhfile.seekg(0,ios::end);
fhfile.write((char*)&fh,sizeof(fh));
fhfile.close();
idhfile.open("idhash.txt",ios::app|ios::binary);
idhfile.seekg(0,ios::end);
idhfile.write((char*)&idh,sizeof(idh));
idhfile.close();
}
else{
FamilyInFile(high,x1);
if(strcmp(x1,fh.family)<0){
fhfile.open("fhash.txt",ios::app|ios::binary);
fhfile.seekg(0,ios::end);
fhfile.write((char*)&fh,sizeof(fh));
fhfile.close();
}//bozorgtar az high
else{
test=0;
mid=low;
while(low<high){
mid=low+((high-low)/2);
FamilyInFile(mid,x1);
if(strcmp(x1,fh.family)>0)
high=mid;
else if(strcmp(x1,fh.family)<0){
low=mid+1;
mid=low;
}//else if
else{
test=1;
break;
}//else
}//while
fhfile.open("fhash.txt",ios::in | ios::out|ios::binary);
if(test==0){
for(i=h;i>=mid;i--){
fhfile.seekg(i*sizeof(fh),ios::beg);
fhfile.read((char*)&fhtemp,sizeof(fhtemp));
fhfile.seekg((i+1)*sizeof(fh),ios::beg);
fhfile.write((char*)&fhtemp,sizeof(fhtemp));
}//for
}//if test
fhfile.seekg(mid*sizeof(fh),ios::beg);
fhfile.write((char*)&fh,sizeof(fh));
fhfile.close();
}//else
low=l;
high=h;
IDInFile(high,&x2);
if(x2<idh.id){
idhfile.open("idhash.txt",ios::app |ios::binary);
idhfile.seekg(0,ios::end);
idhfile.write((char*)&idh,sizeof(idh));
idhfile.close();
}
else{
test=0;
mid=low;
while(low<high){
mid=low+((high-low)/2);
IDInFile(mid,&x2);
if(x2>idh.id)
high=mid;
else if(x2<idh.id){
low=mid+1;
mid=low;
}
else{
test=1;
break;
}
}
idhfile.open("idhash.txt",ios::in | ios::out|ios::binary);
if(test==0){
for(i=h;i>=mid;i--){
idhfile.seekg(i*sizeof(idh),ios::beg);
idhfile.read((char*)&idhtemp,sizeof(idhtemp));
idhfile.seekg((i+1)*sizeof(idh),ios::beg);
idhfile.write((char*)&idhtemp,sizeof(idhtemp));
}
}
idhfile.seekg(mid*sizeof(idh),ios::beg);
idhfile.write((char*)&idh,sizeof(idh));
idhfile.close();
}
}
}
long GetIDofFamily(int founded){
fhash hash;
long pos=founded*sizeof(hash);
fstream fhfile;
fhfile.open("fhash.txt",ios::in |ios::binary);
fhfile.seekg(pos,ios::beg);
fhfile.read((char*)&hash,sizeof(hash));
fhfile.close();
return hash.id;
}
void Delete(int founded){
idhash hash;
Student st_temp;
long pos=founded*sizeof(hash);
fstream file,idhfile;
idhfile.open("idhash.txt",ios::in |ios::binary);
idhfile.seekg(pos,ios::beg);
idhfile.read((char*)&hash,sizeof(hash));
idhfile.close();
file.open("student.txt",ios::in | ios::out |ios::binary);
file.seekg(hash.adrs,ios::beg);
file.read((char*)&st_temp,sizeof(st_temp));
st_temp.del='1';
file.seekg(hash.adrs,ios::beg);
file.write((char*)&st_temp,sizeof(st_temp));
file.close();
}
void Edit(int founded){
idhash hash;
Student st_temp;
long pos=founded*sizeof(hash);
fstream file,idhfile;
idhfile.open("idhash.txt",ios::in|ios::binary);
idhfile.seekg(pos,ios::beg);
idhfile.read((char*)&hash,sizeof(hash));
idhfile.close();
file.open("student.txt",ios::in | ios::out |ios::binary);
file.seekg(hash.adrs,ios::beg);
file.read((char*)&st_temp,sizeof(st_temp));
st_temp.edit='1';
file.seekg(hash.adrs,ios::beg);
file.write((char*)&st_temp,sizeof(st_temp));
file.close();
file.open("student.txt",ios::in | ios::out |ios::binary);
file.seekg(hash.adrs,ios::beg);
st_temp.edit='0';
cout << "enter new name : ";
cin >> st_temp.name;
file.write((char*)&st_temp,sizeof(st_temp));
file.close();
}
int main(){
Student st1,st2;
fhash fh;
idhash idh;
int quit=0,select,count=0,founded;
long id;
char family[30]={"0"};
fstream file,fhfile,idhfile;
file.open("student.txt",ios::in | ios::out |ios::binary);
file.close();
fhfile.open("fhash.txt",ios::in | ios::out |ios::binary);
fhfile.close();
idhfile.open("idhash.txt",ios::in | ios::out |ios::binary);
idhfile.close();
count=GetRecordCount();
while(!quit){
system("cls");
cout << "1: insert" << endl;
cout << "2: search by id" << endl;
cout << "3: search by family" << endl;
cout << "4: delete" << endl;
cout << "5: edit" << endl;
cout << "6: list not complete edited records" << endl;
cout << "7: quit" << endl;
cout << endl;
cout << "enter your select : ";
cin >> select;
cout << endl;
switch(select){
case 1:
cout << "enter id : ";
cin >> st1.id;
founded=BinarySearchID(st1.id,0,count-1);
if(!ExistID(founded,&st2)){
cout << "enter name : ";
cin >> st1.name;
cout << "enter family : ";
cin >> st1.family;
st1.del='0';
st1.edit='0';
Insert(st1,0,count-1);
count++;
}
else{
cout << "ID already exists!";
getch();
}
break;
case 2:
cout << "enter id : ";
cin >> id;
founded=BinarySearchID(id,0,count-1);
if(ExistID(founded,&st1)){
cout << "name : " << st1.name << " - "
<< "family : " << st1.family;
getch();
}
else{
cout << "ID not exists!";
getch();
}
break;
case 3:
cout << "enter family : ";
cin >> family;
founded=BinarySearchFamily(family,0,count-1);
id=GetIDofFamily(founded);
founded=BinarySearchID(id,0,count-1);
if(ExistID(founded,&st1)){
cout << "id : " << st1.id << " - "
<< "name : " << st1.name << " - "
<< "family : " << st1.family;
getch();
}
else{
cout << "family not exists!";
getch();
}
break;
case 4:
cout << "enter id : ";
cin >> id;
founded=BinarySearchID(id,0,count-1);
if(ExistID(founded,&st1)){
cout << "name : " << st1.name << " - "
<< "family : " << st1.family << endl;
Delete(founded);
cout << "deleted!";
getch();
}
else{
cout << "ID not exists!";
getch();
}
break;
case 5:
cout << "enter id : ";
cin >> id;
founded=BinarySearchID(id,0,count-1);
if(ExistID(founded,&st1)){
cout << "name : " << st1.name << " - "
<< "family : " << st1.family << endl;
Edit(founded);
}
else{
cout << "ID not exists!";
getch();
}
break;
case 6:
cout << "--------------------------------" << endl;
file.open("student.txt",ios::in|ios::binary);
file.read((char*)&st1,sizeof(st1));
while(!file.eof()){
if(st1.edit=='1')
cout << st1.id << " - " << st1.name << " - " << st1.family << endl;
file.read((char*)&st1,sizeof(st1));
}
file.close();
cout << "--------------------------------" << endl;
getch();
break;
case 7:
quit=1;
}
}
return 0;
}
سورس کد کامل بازی تیک تاک تو با استفاده از سی پلاس پلاس و OpenGL به صورت دو نفره:
الگوریتم و سورس کامل برنامه پیدا کردن نقاط برخورد بین خطوط در صفحه مختصات در سی پلاس و OpenGL
به همراه توضیحات کامل آن:
برنامه آموزشی بازی مار به صورت غیر گرافیکی مناسب دانشجویان تازه وارد با زبان سی پلاس پلاس:
الگوریتم های رسم انواع دایره (توپر، توخالی، ممتد) در سی پلاس پلاس به همراه توضیحات مربوطه:
سلام دوستان عزیز.
فایل هدر برای محاسبات صحیح بزرگتر از 64 بیت :
IntX.h
چند تا نوع صحیح هم تعریف کردم با اندازه های 128 و 256 و 512 و 1024و 2048 بیت که می تونید بجای اینها از یک تکه از حافظه مثل آرایه ای از بیتها ، با اندازه ی دلخواه خودتون هم استفاده کنید و توابع جمع و تفریق و ضرب و تقسیم و عملیات بیتی همشون با گرفتن اشاره گر کار میکنن و سایز عددتون رو هم می پرسن. پس با هر اندازه ای می تونید محاسبات انجام بدید ولی باید دو تا عددی که مثلا با هم جمع یا ضرب میشن از نظر سایز حافظه اندازه ی هم باشن.
IntX_cpp.zip
فایل یونیت دلفی IntX.pas :
https://barnamenevis.org/showthread.p...A8%DB%8C%D8%AA
آخرین ویرایش به وسیله Ananas : یک شنبه 08 دی 1392 در 01:10 صبح
برنامه اعداد
JollyJumper
&
Variance
/*Jollyjumper*/
/*9122360017*/
# include <stdio.h>
main()
{
int i ,Counter ,Tafazol[3000] ,Number[3000] ;
bool shart=true;
printf("*** Enter your numbers ***\n");
scanf("%d",&Number[1]);
Counter=Number[1];
for(i=0;i<Counter;i++)
scanf("%d",&Number[i]);
for(i=1;i<Counter;i++)
{
Tafazol[i]=Number[i]-Number[i+1];
if(Tafazol[i]<0)
Tafazol[i]=Tafazol[i]*(-1);
}
for(i=1;i<Counter;i++)
{
if(Tafazol[i]<Tafazol[i+1] || Tafazol[i]-Tafazol[i+1]!=1)
shart=false;
break;
}
if(shart==true)
printf("Jolly\n");
else if(shart==false)
printf("Not Jolly\n");
}
/*Variance*/
/*9122360017*/
# include <stdio.h>
main()
{
int i;
int x[15];
double Avg,Var,Siqma=0,Sum=0;
printf("*** Enter 15 numbers ***\n");
for(i=0;i<15;i++)
{
scanf("%d",&x[i]);
Sum=Sum+x[i];
}
Avg=Sum/15;
for(i=0;i<15;i++)
Siqma=Siqma+((x[i]-Avg)*(x[i]-Avg));
Var=Siqma/14;
printf("Variance= %f",Var);
}
سطح: مبتدی
توسط این کد، برنامه پس از اجرا شدن نمرات 5دانش آموز رو به ترتیب دریافت کرده و آنها را به ما نشان میدهد.
اهداف:
1- آشنایی بیشتر با آرایه ها
2- آشنایی بیشتر با حلقه for
کامپایلر برنامه Visual C++ 2012
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
shoroo:
int adad[5];
int i(0);
for (i=0 ; i<5 ; i++)
{
cout<<"nomreye danesh amuze shomare " << i+1 << "ra vared konid.\n";
cin>>adad[i];
}
cout<<"\nshomare\t\tnomre\n-------------------------\n";
for(i=0;i<5;i++)
{
cout<<i+1 <<"\t\t" << adad[i] << "\t|\n";
}
cout<<"-------------------------\n\n";
goto shoroo;
}
هرگونه مشکل یا سوالی بود در خدمتم.
گل يا پوچ ساده.
اين گل يا پوچ خيلي سادست نياز به توپيح نداره.
گرافيكشم ضعيفه چون زياد گرافيك بلد نيستم.
#include <dos.h>;
#include <iostream.h>;
#include <conio.h>;
#include <stdlib.h>;
#include <graphics.h>;
#include <stdio.h>;
int getkey(void )
{
int key,low,high;
key=getch();
return (key) ? key : getch()+256;
}
void main()
{
int gd = DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
int x=20;
while(x<140)
{
x+=20;
rectangle(x,x,600-x,450-x);
delay(500);
}
outtextxy(255,190,"WRITTEN BY ") ;
delay(500);
outtextxy(240,240,"M") ;
delay(500);
outtextxy(240,240,"Mo") ;delay(500);
outtextxy(240,240,"Moh") ;delay(500);
outtextxy(240,240,"Moha") ;delay(500);
outtextxy(240,240,"Moham") ;delay(500);
outtextxy(240,240,"Mohamm") ;delay(500);
outtextxy(240,240,"Mohamma") ;delay(500);
outtextxy(240,240,"Mohammad") ;delay(500);
outtextxy(240,240,"Mohammad Mahdi") ;
delay(1000);
clrscr();
x=20;
while(x<140)
{
x+=20;
rectangle(x,x,600-x,450-x);
delay(500);
}
outtextxy(255,190,"Bazie Gol ya Pooch") ;delay(500);
clrscr();
int i=1;
do{
int gol = random(2);
if(gol == 0) gol = 2;
int pgol;
outtextxy(50,100,"fek mikony Gol too kodoome?\n") ;
ellipse(100,220,0,360,50,50);
outtextxy(100,220,"1");
ellipse(300,220,0,360,50,50);
outtextxy(300,220,"2");
pgol = getkey();
cout<<pgol;
if(pgol == 48)
{
i=0;
}
if(pgol == 49)
pgol = 1;
if(pgol == 50)
pgol = 2;
if(pgol == gol){
if(gol == 1){outtextxy(100,240,"Bordy") ;}
else{outtextxy(300,240,"Bordy") ;}
delay(750);
}else if(pgol!= gol){ if(pgol!=48){
if(gol == 2){outtextxy(300,240,"Backhty\ngol to in bood");}
else{outtextxy(100,240,"Backhty\ngol to in bood");
}
delay(750);}
}
clrscr();
}while(i!=0);
}
اين برنامه نوشته شده در turbo C++ هست.
فايل exe و cpp :
GOL.zip
با سلام خدمت همه دوستان من در حال حاضر مشغول نوشتن برنامه ای برای یک رستوران به زبان ++C هستم که قرار شامل بانک اطلاعاتی و غیره باشد. برای اینکه از باری از روی دوشم کم کنم و هم اینکه زودتر کار را تحویل بدم دنبال سورس آماده برنامه رستوران به زبان ++C هستم تا تغییرات لازم را بر آن اعمال کنم ولی فقط سورس این برنامه به زبان #C را پیدا کردم این شد که اینجا پست گذاشتم تا کسی سورس این برنامه رو داره بهم بده.
پینوشت1: برنامه رستوران اطلاعات غذا و مواد اولیه رو گرفته و در فایل ذخیره میکند.
پینوشت2: پیش از این تاپیکی در همین مورد زده بودم که مدیران با برداشت اینکه درخواست من حل تمرین است تاپیک را بستند که امیدوارم با همان سوءتدبیر این پست را پاک نکنند.
سلام خدمت دوستان این برنامه مساحت و محیط اشکال هندسی رو محاسبه میکنه برنامه ساده ای هستش ولی برای آموزش استفاده از switch خوبه.
برای استفاده باید یکی از اعداد که برای انتخاب نوع شکل مورد نظر هستش رو بزنید و Enter کنید بعد مقادیر لازم رو وارد کنید.
(با برنامه ++ DEV C ) نوشتم
فایل برنامه :
C++ Code.rar
#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)%1 0);
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 <conio.h>
#include <iostream.h>
int gcd(int,int);
int main()
{
int x,y;
cout<<"enter amount for x and y:";
cin>>x>>y;
int k=gcd(x,y);
cout<<k;
getch();
return 0;
}
int gcd(int x,int y)
{
if(y==0)
return x;
else
return gcd(y,x&y);
}//end
سلام دوستان.من یه پروژه ای ساختم به نام : ارتباط سریال با میکرو از طریق RS232
که از کامپیوتر اطلاعات رو میدیم و میکرو روی ال سی دی 2*16 نمایش میده
الان فقط یه مشکل دارم.تو برنامه کلیدی برای پاک کردن چیزی که مینویسیم و جابجایی بین دو سطر تعریف نشده و مجبورم برای پاک کردن چیزی که مینویسم از RESET میکرو استفاده کنم.الان هم من فقط فایل HEX رو دارم.چجوری میشه این تغیر رو اعمال کرد؟ آیا این HEX رو میشه به C تبدیل کرد یا کسی برنامه این پروژه رو سراغ داره ؟
یه سوال دیگه ! برای اینکه کلیدی برای پاک کردن (Clear) کردن تعریف کنم از چه آرایه ای باید استفاده کنم ؟
#include <iostream.h>
#include <conio.h>
void main()
{
int x1[99]={0}, x2[99]={0}, out[99]={0},i=-1,i2=-1,count;
char temp[99];
cout<<"Enter the first number:"<<endl; //get 1st number
do //get it using getche()
{
i++;
temp[i]=getche();
}while(temp[i]!=13);
i--;
int ii=i;
for(int c=0;c<=i;C++) //convert 1st number from char to int
{
x1[c]=temp[ii]-48;
ii--;
}
ii=i;
cout<<"\n\nFirst number: ";
for(;ii>=0;ii--)
cout<<x1[ii];
cout<<endl;
cout<<"\nEnter the second number:"<<endl; //get 2nd number
do //get it using getche()
{
i2++;
temp[i2]=getche();
}while(temp[i2]!=13);
i2--;
ii=i2;
for(c=0;c<=i2;C++) //convert 2nd number from char to int
{
x2[c]=temp[ii]-48;
ii--;
}
cout<<"\n\nSecond number: ";
ii=i2;
for(;ii>=0;ii--)
cout<<x2[ii];
count=(i>i2)?i:i2; //recognize biggest array
int ex=0, temp2, temp3; //define some vars for temporary number and the extra
for(ii=0;ii<=count;ii++) //+ the arrays
{
temp2=(x1[ii]+x2[ii]);
temp2+=ex;
if(temp2<10)
out[ii]=temp2;
else
{
temp3=(temp2/10);
ex=temp3;
temp3*=10;
out[ii]=(temp2-temp3);
}
}
cout<<"\n\nResult:"<<endl;
for(;count>=0;count--)
cout<<out[count];
}
با سلام خدمت دوستان
پروژه ی بازی تنیس با اپن جی ال که دارای هوش مصنوعی نیز می باشد که پروژه ی درس گرافیک می باشد را از اینجا می تونید دانلود کنید:
دانلود
امیدوارم به درد بخوره
موفق و پیروز باشید.:4::4::)
تصویر:
نمونه فایل اجرایی:
Tennis.rar -
آخرین ویرایش به وسیله sampad_abbas1370 : یک شنبه 22 دی 1392 در 01:18 صبح
خواهش میکنم،
الان برای من یه سوالی پیش اومد که توی پست قبلی فراموش کردم بپرسم، برنامتون توی کنسول اجرا میشه یا MDI/SDI هست؟ هرچند از اونجایی که برای دانشگاه هست و با c نوشتید فکر کنم تو کنسول اجرا بشه، به همین خاطر توضیحات کنسول رو میزارم، البته اگر ویژوال باشه کار زیادی نداره، فقط یه text box باید بزارید که خاصیت read_only اون رو فعال کرده باشید و اون متغیر که نمایانگر ثانیه هست رو اونجا نمایش بدید.
اما برای کنسول:
STD_OutPut Handle یک تابعی هست برای کنترل کردن صفحه ی کنسول، توی این بخش ما نیاز داریم تا بتونیم موقعیت cursor در صفحه ی کنسول بدون ایجاد تغییر در متن های چاپ شده تغییر بدیم. برای اینکار یه تابعی رو با استفاده از همین STD_Handel می نویسیم که این کار رو برای ما انجام بده، تابع به شکل زیر میشه:
void gotoxy(int x,int y) // this function will move cursor in the screen
{
HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
if (INVALID_HANDLE_VALUE != hConsole)
{
COORD pos = {x, y};
SetConsoleCursorPosition( hConsole, pos );
}
}
بعد هم مثلا شما میخواید ثانیه شمار رو در مختصات x = 25 و y = 1 نمایش بدید، برای اینکار در ابتدای نمایش که باید cursor رو به مختصات فوق ببرید و متغیر حاوی ثانیه رو چاپ کنید، از دفعه ی بعد برای چاپ مجدد بدون تغییر مجدد در صفحه، باید اول ثانیه ی قبلی رو پاک کنید از صفحه ی کنسول، برای انجام اینکار ابتدا باید cursor رو به یک واحد جلوتر از اون خروجی نتقال بدیم که اینجا میشه y = 1, x = 26 ، بعد از این کار هم برای پاک کردن اون خروجی ( تنها پاک کردن یک واحد) و چاپ خروجی جدید، کافیه از دستور زیر استفاده کنید:
cout<<"\b"<<time_calculator
این دستورش تو C++ بود، توی c هم دستور پاک کردن همین("\b") هست، فقط کافیه با تابع printf اجراش کنید.
اگر سوالی بود در خدمت هستم.
آخرین ویرایش به وسیله amirtork : پنج شنبه 05 تیر 1393 در 22:57 عصر دلیل: اضافه کردن خط آخر :دی
بازی سوپر ساده اعداد
توضیح توی اجرای برنامه هست
#include <cstdlib>
#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int a=0;
int n=0;
int b=0;
int level=1;
srand(time(0));
cout<<"Inter a level between 1 and 5"<<endl;
start:
cin>>level;
if(level>5 || level<0)
{
cout<<"Choose an integer number between 1 and 5"<<endl;
goto start;
}
cout<<"I choose a number in 1 to "<<(level*200) << " range.Guess it!"<<endl;
a=1+(rand()%(level*200));
for(int j=1;;j++)
{
cin>>b;
if (b<a)
{
cout<<"The number is bigger than this"<<endl;
n++;
}
else if(b>a)
{
cout<<"The number is smaller than this"<<endl;
n++ ;
}
else if(b=a)
{
cout<<"You choose the correct number.Your score is "<<(100-j)*10<<"."<<endl;
break;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
قطعه کدی که یه عدد به عنوان تعداد ازت میگیره و تا اون تعداد، دنباله فیبوناچی رو چاپ میکنه.
#include <stdio.h>
int main()
{
start:
printf("chand adad az serie fibonachi? ");
unsigned long int i,n,n_1=1,n_2=0;
scanf("%d",&n);
if (n<47 && n>1)
{
printf("\nn(0)=0\nn(1)=1");
for (i=2;i<=n;i++)
{
n_1=n_1+n_2;
n_2=n_1-n_2;
printf("\nn(%d)=%d",i,n_1);
}
flag:
printf("\n\n\n AYA AZ AVAL SHOROO KONIM? (Y)");
char e;
scanf("%s",&e);
if (e=='y' || e=='Y')
{
printf("\n");
goto start;
}
else
return(0);
}
else
printf("\nError! Enter a valid number. (between 2 and 46)");
goto flag;
}
هرسوالی بود در خدمتم
پاسخ را به زبان C براتون نوشتم، برنامه اول یه عدد از شما میگیره که شما میتونین همون 1000000 رو وارد کنید. بعد تمام اعداد اولی که جمعشون زیر 1000000 میشه رو واستون چاپ میکنه نهایتا هم جمعش رو بهتون میگه.سلام سوال 50 project euler:
https://projecteuler.net/problem=50
عدد اول 41 می توانند بصورت 6 عدد اول متوالی نوشته شود:
2+3+5+7+11+13=41
این دنباله بزرگترین دنباله از اعداد اول متوالی زیر 100 است که جمع ان ها نیز یک عدد اول می شود.
حال کدام عدد اول زیر 1 میلیون می تواند از مجموع بیشترین تعداد عدد اول متولی درست شود؟؟
#include <stdio.h>int main()
{
unsigned long int i,m=0,n,h,x;
printf("adad ra vared konid: ");
scanf("%d",&x);
for (i=1;i<=x;i++)
{
n=0;
for (h=1;h<=i;h++)
{
if (i%h==0)
n++;
}
if (n==2)
{
if (m+i>x)
break;
else
{
printf("%d\t",i);
m=m+i;
}
}
}
printf("\n\n -- adade %d bozorgtarin adade zire %d ast ke az jame bishtarin tedade adade avale motevali tashkil shode ast.\n",m,x);
}
اگه سوالی بود در خدمتم
تکه کدی که با اجراش یه فایل txt درست میشه و تمام کاراکترهارو (+اونایی که هیچ کیبوردی نداره) میریزه توش که میتونین ازشون استفاده کنین:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream fout("out.txt");
char a;
for(int i=0;i<256;i++)
{
a=i;
fout<<a<<" ";
}
return 0;
}
توی این برنامه به جای قرار دادن همه اعداد تو یه آرایه، میایم اعداد رو تک تک توی یه متغیر میذاریم، برسیش میکنیم و بعد عدد بعدی رو قرار می دیم!سئوال بعدی در مورد چگونگی تجزیه اعداد هست , باید برنامه ای نوشته بشه که عدد n رو بگیره و اون رو تجزیه کنهو با فرمت مناسب چاپ کنه . مشکلم اینه که نمیذاره از تابع و آرایه استفاده کنم . بنابراین نمیدونم باید چیکار کنم . ممنون میشم این راهنمایی کنید .
سوال: برنامه ای بنویسید که از کاربر دو سر بازه را گرفته و اعداد اول بین دو بازه را چاپ کند.
کد برنامه به زبان C به این صورته:
#include<stdio.h>
int main()
{
start:
unsigned long int x,y,i,h,n;
printf("adad haye aval ra az che adadi mohasebe konam? ");
scanf("%d",&y);
printf("ta che adadi? ");
scanf("%d",&x);
if (x<1 || y<1 || y>=x)
{
printf("\nError, Enter a valid number!\n");
goto start;
}
else
{
for (i=y;i<=x;i++)
{
n=0;
for (h=1;h<=i;h++)
{
if (i%h==0)
n++;
}
if (n==2)
printf("%d\t",i);
}
}
}
سوالی بود در خدمتم
2 برنامه ای که خروجی زیر نشون بدن رو لازم دارم پلیز تو نوشتنشون مشکل دارم
fawfsf.pngfawf.png
برای بدست اوردن ماکس ومین با while از بین اعداد نامشخص و تازمانی که 0 وارد نشده یعنی در ابتدا تضمین شود اولین عدد صفر نباشد
خواهش میکنم کمک کنین خیلی فوریه
مرسی از دوستان....برای من که خیلی مفید بود