PDA

نسخه کامل مشاهده نسخه کامل : تبدیل c به c++



abdolhakim
28-05-2012, 00:52
سلام دوستان
حالتون خوبه ؟ خب خدا رو شکر :27:
من کد برنامه C دارم میخام تبدیلش کنم به ++C
آگه کسی میدونه چطور میشه اینکارو انجام بدم لطف کنه بگه :46:

A M ! N
28-05-2012, 02:57
سلام..ما که خوبیم شمام خوبی ؟ :دی
سورسهای C رو میشه با کامپایلر ++ C اجرا کرد در حالی که بالعکس رو نمیشه.

با کامپایلر ++ C سورس رو run کردین ؟ از Borland استفاده کنید. ببینید چی میشه ولی برای تبدیل کامل فرمت سورس از لینک پایین استفاده کنید :

[ برای مشاهده لینک ، لطفا با نام کاربری خود وارد شوید یا ثبت نام کنید ]

حتما Manual رو هم بخونین که بدونین باید چیکار کنید، مثلا برای اجرای اسکریپت گفته شده که به Python هم نیاز هستش.

Ghaioom
28-05-2012, 05:13
سلام. ما خوبیم شما چی در سلامتی کامل به سر میبری هو؟! :31:

آنچنان فرقی بین کدهای همدیگه ندارن. مثلا گاهی کدهاش رو مثلا پرینت بود فک کنم من cout مثل اینکه کرده بودمش کار کرد.
یادم نیست بقیه ولی میشد دستی درست کرد.
شاید کد رو بزارین ببینیم بشه گفت.

abdolhakim
28-05-2012, 06:37
سلام..ما که خوبیم شمام خوبی ؟ :دی
سورسهای C رو میشه با کامپایلر ++ C اجرا کرد در حالی که بالعکس رو نمیشه.

با کامپایلر ++ C سورس رو run کردین ؟ از Borland استفاده کنید. ببینید چی میشه ولی برای تبدیل کامل فرمت سورس از لینک پایین استفاده کنید :

[ برای مشاهده لینک ، لطفا با نام کاربری خود وارد شوید یا ثبت نام کنید ]

حتما Manual رو هم بخونین که بدونین باید چیکار کنید، مثلا برای اجرای اسکریپت گفته شده که به Python هم نیاز هستش.
داش من خوندم چیزی حالیم نشد :13:

اگه سورس بدم شما میتونید اوک کنید ؟ :11:

A M ! N
28-05-2012, 11:46
آخه چرا داداش ؟ :دی
سورس رو بزار ، یه فکری به حالش میکنیم :10:

abdolhakim
28-05-2012, 20:24
بیا داداش اینم سورس


#include<iostream>
#include<string.h>
using namespace std;
class Car{
/*this is the definition of our class*/
public:
char make[100];
char model[100];
int partno;
char partName[100];
float price;
int quantity;
void car(char* make1,char* model1, int partno1, char* partName1, float price1, int quantity1) {
strcpy(make,make1);
strcpy(model,model1);
partno=partno1;
strcpy(partName,partName1);
price=price1;
quantity=quantity1;
}
};
int show(){
int k=0;
cout<<"[1] Add part\n[2] Update part\n[3] Remove part\n[4] List inventory\n[5] Parts whose quantity < 5\n[6] Parts above a given price\n[7] Parts above the average price\n[8] Stock statistics\n[9] Exit\n\n\n\nEnter your choice: ";
cin>>k;
cout<<"\n";
return k;
}
void reloadfile(int count, Car* car_object){
FILE * fout=fopen("inventory.txt", "w");
//make model partNo Quantity price partName
fprintf(fout,"make model partNo Quantity price partName\n");
for(int i=0;i<count;i++){
if(car_object[i].partno>0){
fprintf(fout,"%s ",car_object[i].make);
fprintf(fout,"%s ",car_object[i].model);
fprintf(fout,"%d ",car_object[i].partno);
fprintf(fout,"%d ",car_object[i].quantity);
fprintf(fout,"%f ",car_object[i].price);
fprintf(fout,"%s",car_object[i].partName);
}
}
fclose(fout);
}
int loadfile(Car * car_object){
char make2[100];
char model2[100];
int partno2;
char partName2[100];
float price2;
int quantity2;
int count=0;
/*
make model partNo Quantity price partName
Pajero NA1H25 1 26 3.65 BLADE W/S WIPER
*/
FILE * fin =fopen("inventory.txt","r");
char str[100];
fgets(str,100,fin);
//printf("%s",str);
while(fgets(str,100,fin)!=NULL){
char * pch;
pch = strtok (str," ");
strcpy(make2,pch);
pch = strtok (NULL, " ");
strcpy(model2,pch);
pch = strtok (NULL, " ");
partno2=atoi(pch);
pch = strtok (NULL, " ");
quantity2=atoi(pch);
pch = strtok (NULL, " ");
price2=atof(pch);
pch = strtok (NULL, "");
strcpy(partName2,pch);
car_object[count].car(make2,model2,partno2,partName2,price2,quantit y2);
count++;
}
return count;
}
void updateItem(int count,Car * car_object){
cout<<"please Enter A,a/R,r if you want to add or remove\n";
char x;
cin>>x;

if(x=='A'||x=='a'){
cout<<"Please Enter Partnumber : ";
int numa,numb;
cin>>numa;
cout<<"\nHow many items do you want to add?\n";
cin>>numb;
for(int i=0;i<count;i++){
if(car_object[i].partno==numa){
car_object[i].quantity+=numb;
}
}
}
else if(x=='R'||x=='r')
{
cout<<"Please Enter Partnumber : ";
int numa,numb;
cin>>numa;
cout<<"\nHow many items do you want to remove?\n";
cin>>numb;
for(int i=0;i<count;i++){
if(car_object[i].partno==numa){
if(car_object[i].quantity > numb){
car_object[i].quantity-=numb;
}
else{
cout<<"Sorry ... this action is impossible\n";
cin>>x;

}
}
}
}
reloadfile(count,car_object);
}
int addItem(int count,Car * car_object){
char make2[100];
char model2[100];
int partno2;
char partName2[100];
float price2;
int quantity2;
cout<<"Stock Control _ Add Item:\n=========================\n";
cout<<"Enter the car make : ";
cin>>make2;
cout<<"Enter the car model : ";
cin>>model2;
cout<<"Enter partNo: ";
cin>>partno2;
cout<<"Enter part name: ";
cin>>partName2;
cout<<"Enter price: ";
cin>>price2;
cout<<"Enter quantity: ";
cin>>quantity2;
car_object[count].car(make2,model2,partno2,partName2,price2,quantit y2);
cout<<"Save (Y,a/N,n): ";
char x;
cin>>x;
if(x=='Y'||x=='y'){
cout<<".....Record saved.\n";
count++;
}
else if (x=='N'||x=='n')
{
cout<<".....Record cancelled.\n";
}
else
cout<<"You did not entered either N,n or Y,y:";
reloadfile(count,car_object);
return count;
}
void list(int count,Car * car_object, int quant, float pri){
//make model partNo Quantity price partName
cout<<"make model partNo Quantity price partName Total_price\n";
for(int i=0;i<count;i++){
if(car_object[i].partno>0 && car_object[i].quantity<quant && car_object[i].price>pri){
cout<<car_object[i].make;
cout<<car_object[i].model;
cout<<car_object[i].partno;
cout<<car_object[i].quantity;
cout<<car_object[i].price;
cout<<car_object[i].partName;
cout<<car_object[i].price*car_object[i].quantity;
}
}
}
void remove(int count, Car * car_object){
cout<<"please Enter your part number to Remove it :";
int num;
cin>>num;
for(int i=0;i<count;i++){
if(car_object[i].partno==num){
car_object[i].partno=-1;
}
}
reloadfile(count,car_object);
}
void statistics(int count, Car * car_object){
/*
Stock statistics such as: the current value of the stock (sum of price*quantity),
the average price, the most expensive item, the least expensive item, the least
stocked item … etc.
*/
int number=0,least=100000;
float sum=0,avg=0,highprice=-1,cheapprice=1000000;
for (int i=0;i<count;i++){
if(car_object[i].partno>0){
sum+= (car_object[i].quantity*car_object[i].price);
avg+=car_object[i].price;
number++;
if(car_object[i].price<cheapprice){
cheapprice=car_object[i].price;
}
if(car_object[i].price>highprice){
highprice=car_object[i].price;
}
if(car_object[i].quantity<least){
least=car_object[i].quantity;
}
}
}
avg=avg/number;
printf("the current value of the stock (sum of price*quantity)= %f\nthe average price: %f\nthe most expensive item: %f\nthe least expensive item : %f\nthe leaststocked item :%d \n",sum,avg,highprice,cheapprice,least);
char x;
cin>>x;
}
void control(){
Car car_object[1000];
int count=loadfile(car_object);
int option;
while(1){
option=show();
if(option==1){
/*
Add a new item. Write a function called addItem() that asks the user to input data of a
new part and then add the data to the parts file (keeping the same file format).
*/
count=addItem(count,car_object);
}
else if(option==2){
/*Update stock level. Write a function called updateItem() that takes as parameter the
partNo and the quantity to be added/removed. Check that enough items are there if the
operation is a remove operation.
*/
updateItem(count,car_object);
}
else if(option==3){
/*
Remove an item. You cannot remove an array element. However, let us use a negative
partNo to indicate a removed item. When saving the arrays to the file, only save items
with positive partNo.
*/
remove(count,car_object);
}
else if(option==4){
/*
List the current inventory in a tabular format. In the last column of this list show the
total price of each item (i.e. price*quantity).
*/
list(count,car_object,1000000,-1);
}
else if(option==5){
/* All items whose quantity field < 5.*/
list(count,car_object,5,-1);
}
else if(option==6){
/*All items whose price is greater than a value provided by the user.*/
cout<<"Enter you price amount\n";
float f;
cin>>f;
list(count,car_object,1000000,f);
}
else if(option==7){
/* All items whose price is greater than the average item price.*/
float avg=0;
int number=0;
for(int i=0;i<count;i++){
if(car_object[i].partno>0){
avg+=car_object[i].price;
number++;
}
}

avg=avg/number;
list(count,car_object,1000000,avg);
cout<<"avg and num = %f , %d \n"<<avg<< number;
}
else if(option==8){
/*
Stock statistics such as: the current value of the stock (sum of price*quantity),
the average price, the most expensive item, the least expensive item, the least
stocked item … etc.
*/
statistics(count,car_object);
}
else if(option==9){
/*EXIT*/
return ;
}
}
}
int main(){
/*this function manages every thing*/
control();
return 0;
}

A M ! N
29-05-2012, 00:28
سلام.

این سورس پایین رو حالا با ++ Dev C امتحان کن:


50685

پسوند رو هم به CPP تغییر بده..

بهترین آرزوها..

Ghaioom
29-05-2012, 04:39
عزیز چقد زیاد بود ما فک کردیم کمه!! :31:

بعدشم این خودش فک کنم c++ هست. نیست؟!
کداش که چنین میگه.

A M ! N
29-05-2012, 13:40
فایل Exe سورس ++C:


.......................50697



بهترین آرزوها..

پرنیان*
29-05-2012, 20:52
ممنون از سایت خوبتون

masterhe3ar
21-08-2012, 19:28
آقایون ازتون خواهش میکنم کمکم کنید،من فردا تحویل پروژه دارم نمیدونم چیکار کنم
کسی هست بتونه پروژه زیرو به هر زبانی که شده واسم بنویسه؟ تورو خدا کمکم کنید

برنامه ای بنویسید که عناصر استک آ با سایز 10 از ورودی دریافت کند سپس با استفاده ار حداقل ساختمان داده اضافی

عناصر استک آ را وارد استک خالی بی کند
به نحوی که ترتیب عناصر در بی همان ترتیب در آ باشد

در دو حالت
الف:
جهت پیاده سازی ساخمان داده های مورد نیاز از آرایه استفاده کنید
ب:
از لیست های پیوندی

اگه کسی تونست واسم میل کنه یا خبرم بده اینم ایمیلم
leila_falah@yahoo.com

ftm73
10-04-2014, 19:16
سلام من یه برنامه ی شجره نامه نویس میخوام ب زبان c++ .از اینترنت برنامشو پیدا کردم اما ب زبان c هستش .

/*
Beginning C, Third Edition
By Ivor Horton
ISBN: 1-59059-253-0
Published: Apr 2004
Publisher: apress

*/

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

struct Family *get_person(void); /* Prototype for input function */
char related(struct Family *pmember1, struct Family *pmember2);
char set_ancestry(struct Family *pmember1, struct Family *pmember2);

struct Date
{
int day;
int month;
int year;
};

struct Family /* Family structure declaration */
{
struct Date dob;
char name[20];
char father[20];
char mother[20];
struct Family *next; /* Pointer to next structure */
struct Family *previous; /* Pointer to previous structure */
struct Family *p_to_pa; /* Pointer to father structure */
struct Family *p_to_ma; /* Pointer to mother structure */
};

void main()
{
struct Family *first = NULL; /* Pointer to first person */
struct Family *current = NULL; /* Pointer to current person */
struct Family *last = NULL; /* Pointer to previous person */

char more = '\0'; /* Test value for ending input */

for( ; ; )
{
printf("\nDo you want to enter details of a%s person (Y or N)? ",
first != NULL?"nother " : "" );
scanf(" %c", &more);
if(tolower(more) == 'n')
break;

current = get_person();

if(first == NULL)
{
first = current; /* Set pointer to first Family */
last = current; /* Remember for next iteration */
}
else
{
last->next = current; /* Set next address for previous Family */
current->previous = last; /* Set previous address for current */
last = current; /* Remember for next iteration */
}
}

current = first;

while(current->next != NULL) /* Check for relation for each person in */
{ /* the list up to second to last */
int parents = 0; /* Declare parent count local to this block */
last = current->next; /* Get the pointer to the next */

while(last != NULL) /* This loop tests current person */
{ /* against all the remainder in the list */
if(related(current, last)) /* Found a parent ? */
if(++parents == 2) /* Yes, update count and check it */
break; /* Exit inner loop if both parents found */

last = last->next; /* Get the address of the next */
}
current = current->next; /* Next in the list to check */
}

/* Now tell them what we know */

/* Output Family data in correct order */
current = first;

while (current != NULL) /* Output Family data in correct order */
{
printf("\n%s was born %d/%d/%d, and has %s and %s as parents.",
current->name, current->dob.day, current->dob.month,
current->dob. year, current->father, current->mother);
if(current->p_to_pa != NULL )
printf("\n\t%s's birth date is %d/%d/%d ",
current->father, current->p_to_pa->dob.day,
current->p_to_pa->dob.month,
current->p_to_pa->dob.year);
if(current->p_to_ma != NULL)
printf("and %s's birth date is %d/%d/%d.\n ",
current->mother, current->p_to_ma->dob.day,
current->p_to_ma->dob.month,
current->p_to_ma->dob.year);

current = current->next; /* current points to next in list */
}

/* Now free the memory */
current = first;
while(current->next != NULL)
{
last = current; /* Save pointer to enable memory to be freed */
current = current->next; /* current points to next in list */
free(last); /* Free memory for last */
}
}

/* Function to input data on Family members */
struct Family *get_person(void)
{
struct Family *temp; /* Define temporary structure pointer */

/* Allocate memory for a structure */
temp = (struct Family*) malloc(sizeof(struct Family));

printf("\nEnter the name of the person: ");
scanf("%s", temp -> name ); /* Read the Family's name */

printf("\nEnter %s's date of birth (day month year); ", temp->name);
scanf("%d %d %d", &temp->dob.day, &temp->dob.month, &temp->dob.year);

printf("\nWho is %s's father? ", temp->name );
scanf("%s", temp->father ); /* Get the father's name */

printf("\nWho is %s's mother? ", temp -> name );
scanf("%s", temp -> mother ); /* Get the mother's name */

temp->next = temp->previous = NULL; /* Set pointers to NULL */

temp->p_to_pa = temp->p_to_ma = NULL; /* Set pointers to NULL */
return temp; /* Return address of Family structure */
}

char set_ancestry(struct Family *pmember1, struct Family *pmember2)
{
if(strcmp(pmember1->father, pmember2->name) == 0)
{
pmember1->p_to_pa = pmember2;
return 1;
}

if( strcmp(pmember1->mother, pmember2->name) == 0)
{
pmember1->p_to_ma = pmember2;
return 1;
}
else
return 0;
}

/* Fill in pointers for mother or father relationships */
char related (struct Family *pmember1, struct Family *pmember2)
{
return set_ancestry(pmember1, pmember2) ||
set_ancestry(pmember2, pmember1);
}

Amirmoo8
24-01-2020, 19:38
سلام داداش

mohamad_79
17-06-2020, 16:15
سلام یه فایل cpp دارم چجوری باید به c تبدیل کنم؟؟؟

کسی هست بتونه راهنمایی کنه ؟:n13::n13:

لطفا کمکم کنید


اینم کدش



#define ([ برای مشاهده لینک ، لطفا با نام کاربری خود وارد شوید یا ثبت نام کنید ]) N 8
#include ([ برای مشاهده لینک ، لطفا با نام کاربری خود وارد شوید یا ثبت نام کنید ]) <stdio.h>
#include ([ برای مشاهده لینک ، لطفا با نام کاربری خود وارد شوید یا ثبت نام کنید ]) <stdbool.h>


void printSolution(int board[N][N])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
printf(" %d ", board[i][j]);
printf("\n");
}
}



bool isSafe(int board[N][N], int row, int col)
{
int i, j;


for (i = 0; i < col; i++)
if (board[row][i])
return false;
for (i=row, j=col; i>=0 && j>=0; i--, j--)
if (board[i][j])
return false;


for (i=row, j=col; j>=0 && i<N; i++, j--)
if (board[i][j])
return false;

return true;
}


bool solveNQUtil(int board[N][N], int col)
{


if (col >= N)
return true;


for (int i = 0; i < N; i++)
{


if ( isSafe(board, i, col) )
{
board[i][col] = 1;

if ( solveNQUtil(board, col + 1) )
return true;
board[i][col] = 0; // BACKTRACK
}
}
return false;
}
bool solveNQ()
{
int board[N][N] = { {0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};

if ( solveNQUtil(board, 0) == false )
{
printf("Solution does not exist");
return false;
}

printSolution(board);
return true;
}

// driver program to test above function
int main()
{
solveNQ();
return 0;
}

pro_translator
26-06-2020, 18:16
از Comeau C/C++ استفاده کن...

mohamad_79
28-06-2020, 16:23
نمیشه هر کاری میکنم:sad: