Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to access the data of different classes which are inherit with another class but i dont know how i can do i have tried as below.. so help me?
here is the sample of my code..
class A{};
class B{};
class C{};
class D:public A,public B,public C{
// here i want to call friend fundition so help me?
};

What I have tried:

friend void result(Islamic,Pakstudy,Computer);// it is decler in different classes like Islamic etc.
void result(Islamic is,Pakstudy pk,Computer cm){
system("cls");
cout<<"\t\t\t\t\t\t\t RESULT OF QUIZ COMMPETATION\t\t\n\n"<<endl;
cout<<"\t\t\t\t\t\t\t Quastion Category: Islamic Study \t\t Total marks \t Obtain Marks "<<endl;
cout<<"\t\t\t\t\t\t\t Round : 1 \t\t 25 \t "<<is.ismarks<<endl;

result(Islammic;Pakstudy;Computer); //here is error ,this an other class in i want to access data but syntex error
Posted
Updated 12-Sep-16 10:26am
Comments
[no name] 12-Sep-16 14:19pm    
"syntex error" if you really mean "syntax error", then yes it is. Go back to your study notes and review how to pass parameters to functions.
CPallini 12-Sep-16 15:54pm    
Could you please elaborate?

1 solution

You call a function with arguments (in your case Islamic, Pakstudy, Computer).
Arguments are separated by commas (,):

result(Islammic,Pakstudy,Computer);

Whether that will fix your friend problem, I don't know without seeing the entire code.

Matt
 
Share this answer
 
Comments
Member 12632487 13-Sep-16 3:08am    
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<string>
#include<windows.h>
#include<fstream>
using namespace std;
class Islamic;
class Computer;
class Pakstudy;
class Menu{
public:
void welcome(){
cout<<"\n\n\n\n\n\t\t\t\t\t\t\t\t\t WELCOME TO THE \n \t\t\t\t\t\t\t\t\tQUIZ COMPETATION \n\n\n"<<endl;
}
void main(){
cout<<" \t\t\t\t\t\t CHOSE THE OPATOIN "<<endl;
cout<<" \t\t\t\t\t\t 1) National and International"<<endl;
cout<<" \t\t\t\t\t\t 2) Computer"<<endl;
cout<<" \t\t\t\t\t\t 3) Islamic"<<endl;
cout<<" \t\t\t\t\t\t 4) Result"<<endl;
}
void profile(string category,float obtmarks){
cout<<"\t\t\t\t\t\t Student Name: \t\t\t\t\t\t "<<endl;
cout<<"\t\t\t\t\t\t Quastion category:"<<category<<" \t\t\t\t\t Round: "<<endl;
cout<<"\t\t\t\t\t\t Starting Time: \t\t\t\t\t\t Remaining Time:"<<endl;
cout<<"\t\t\t\t\t\t Total Marks: 25"<<setw(20)<<"\t\t\t\t\t\t Obtaing Marks:"<<obtmarks<<endl;
}
};
class Islamic{
protected:
float ismarks;
int istmarks;

public:
Islamic();
void roundfirst(){
cout<<" islimic round1"<<endl;

}
friend void result(Islamic,Pakstudy,Computer);

};
Islamic::Islamic(){
ismarks=0;
istmarks=25;
}
class Computer{
protected:
float commarks;
int comtmarks;
public:
Computer();
void roundfirst(){
string question;
string option1;
string option2;
string option3;
string option4;
int count = 0;
int answers[5];
int marks = 0;
int realAnswers[5] = {2,4,3,1,1}; // real answers suppose first index for first question
ifstream readQuestions("computer.txt");
while(count < 5){
getline(readQuestions, question);
getline(readQuestions, option1);
getline(readQuestions, option2);
getline(readQuestions, option3);
getline(readQuestions, option4);
cout << question << "\n";
cout << "1: " << option1 << " 2: " << option2 << " 3: " << option3 << " 4: " << option4 << "\n";
cin >> answers[count++];
}
for(int i=0; i<5; i++){
if(answers[i] == realAnswers[i]){
marks = marks + 10;
}
else {
marks=marks-5;
}
}

cout << "You have got " << marks << " Marks";
// after this you can compare answers array index to your real answers
}
friend void result(Islamic,Pakstudy,Computer);
};
Computer::Computer(){
commarks=0;
comtmarks=25;
}
class Pakstudy{
protected:
float pakmarks;
int paktmarks;
public:
Pakstudy();
void roundfirst(){
cout<<" pakstudy round1"<<endl;

}
friend void result(Islamic,Pakstudy,Computer);
};
Pakstudy::Pakstudy(){
pakmarks=0;
paktmarks=25;
}
void result(Islamic is,Pakstudy pk,Computer cm){
system("cls");
cout<<"\t\t\t\t\t\t\t RESULT OF QUIZ COMMPETATION\t\t\n\n"<<endl;
cout<<"\t\t\t\t\t\t\t Quastion Category: Islamic Study \t\t Total marks \t Obtain Marks "<<endl;
cout<<"\t\t\t\t\t\t\t Round : 1 \t\t 25 \t "<<is.ismarks<<endl;
}
class Connection:public Islamic,public Computer,public Pakstudy,public Menu
{
protected:
char back;
int choice;
public:
void showmenu(){
Menu::welcome();
Sleep(7000);
m:
Menu::main();
cin>>choice;
}
void operation(){
if(choice==1){
system("cls");
Menu::welcome();
Menu::profile("Pakstudy",pakmarks);
Pakstudy::roundfirst();
}
else if(choice==2){
system("cls");
Menu::welcome();
Menu::profile("Computer",commarks);
Computer::roundfirst();
}
else if(choice==3){
system("cls");
Menu::welcome();
Menu::profile("Islamic",ismarks);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900