#include<iostream>
#include<string>
using namespace std;
class A{
private:
string id;
string work; // same as class B
int salary;
public:
void getid(string _id){
id=_id;
}
string returnid(){
return id;
}
void getwork(string _work){
work= _work;
}
string returnwork(){
return work;
}
/*
if i need to use the data of objects of class B, how can i do this?
void calculation(){
salary= the price of the same work in class B
let say. all work
salary = b[0].returnprice()+b[1].returnprice()+b[2].returnprice()+b[3].returnprice();
so how can i make it possible?
*/
};
class B{
private:
string work;
string price;
void getwork(string _work){
work= _work;
}
string returnwork(){
return work;
}
void getprice(int _price){
price= _price;
}
int returnprice(){
return price;
}
};
A a[50];
B b[50];
string work[]={"001","002","003","004"};
int price[]={5000,6000,7000,8000};
void initializeB(){ // make 4 objects of class B
for(int i=0; i<4; i++){
b[i].getwork(work[i]);
b[i].getprice(price[i]);
}
}
int main(){
initializeB();
return 0;
}
vampersie 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.