PDA

View Full Version : سوال: چگونه در یک کلاس اسم را وارد کنم؟!



aapalireza
جمعه 21 خرداد 1389, 22:57 عصر
سلام
من کلاسی تعریف کردم و وقتی می خواهم نام را وارد کنم برنامه هنگ می کند.
لطفا اگر می توانید مشکل برنامه ی مرا برطرف کنید.


// Proje -Class karmand&Modir
//Alireza Akhavan Pour
#include <iostream.h>
#include <stdio.h>
#include <conio.h> // for clrscr

//class body -karmand
class karmand{
friend class modir;
//
private:

//
public:
float saat,salary;
void set(float a,float b){saat=a;salary=b;}
void personal(char *cod1,char *name1);
char *cod,*name; // cod => shomare peroneli
static float bime,maliat; // Static
}ob[5];//end of class - karmand
void karmand::personal(char *cod1,char *name1){
cod=cod1;name=name1;}
//class body -modir
class modir{
public:
void calculate(float saat1,float salary1)
{
float hm,hk,m_bime,m_maliat;//hm=>hoghooghe mahane -- hk=>khoghooghe khales
float tafavot;
hm=saat1*salary1;
tafavot=hm-700000;
if (hm<=700000)
m_maliat=hm*ob[1].maliat;
else
m_maliat=700000*ob[1].maliat+tafavot*0.12;
m_bime=ob[1].bime*hm;
hk=hm-(m_maliat+m_bime);
//show:
cout<<"\n\tHoghooghe mahane:"<<hm;
cout<<"\n\tmaliat:"<<m_maliat;
cout<<"\n\tbim:"<<m_bime;
cout<<"\n\tHoghooghe khales:"<<hk;
}
}obj[5];//end of modir
//tavabe body

float karmand::bime=0.07; //=> bime=%7
float karmand::maliat=0.10; //=> maliat=%10

//main body
void main(){
float s,h;
char *n1,*c1;
for(int i=0;i<5;i++)
{
cout<<"\nkarmande"<<(i+1)<<":\n";
cout<<"\tName: ";
cin>> n1;
cout<<"\tcod: ";
cin>> c1;
cout<<"\tsaate karkard: ";
cin>>s;
cout<<"\thoghooghe 1 saat: ";
cin>>h;
ob[i].set(s,h);
ob[i].personal(n1,c1);
}//end for
cout<<"\n************************\n";
for(int i=0;i<5;i++)
{
cout<<"\n\nkarmande"<<(i+1)<<":";
obj[i].calculate(ob[i].saat,ob[i].salary);
}
getche();
}// end of main

aapalireza
شنبه 22 خرداد 1389, 18:26 عصر
طفا پاسخ مرا بدهید!:گیج: