0% found this document useful (0 votes)
44 views2 pages

Mid Lab Oop

The document contains code for 3 problems. The first problem defines pointers to variables and uses them to input and output values. The second problem defines variables to calculate the sum of digits in a number. The third problem defines a student class with attributes like name and marks, and methods to input student data, calculate average and maximum marks, and output the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Mid Lab Oop

The document contains code for 3 problems. The first problem defines pointers to variables and uses them to input and output values. The second problem defines variables to calculate the sum of digits in a number. The third problem defines a student class with attributes like name and marks, and methods to input student data, calculate average and maximum marks, and output the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//‫حل السوال االول من امتحان الميد‬

#include <iostream>

using namespace std;

int main()
{
int x,y;
int *p1,*p2,*p3;
p1=&x;
p2=&y;
p3=new int;
cout<<"enter value\n";
cin>>(*p1)>>(*p2)>>(*p3);
cout<<"x= "<<(*p1)<<" "<<"y= "<<(*p2)<<" "<<"p3= "<<(*p3);

return 0;
}
***********************************************************************************
********
//‫حل السؤال الثاني‬
#include <iostream>
using namespace std;
int main()
{
int num1, num2, r, sum=0;
cout << " Input a number: ";
cin >> num1;
num2 = num1;
for(int i=num1;i>0;i=i/10)
{
r = i % 10;
sum =sum+r;
}
cout << "the summation result " << num2 << " is : " << sum << endl;
return 0;
}
***********************************************************************************
***********
//‫حل السؤال الثالث‬

#include <iostream>
using namespace std;
class student{
string sname;
int marks[5];

public:
void assign(){

cout<<"name of student : ";


cin>>sname;
cout<<"enter 5 mark:\n";
for(int i=0;i<5;i++){
cout<<"mark "<<i+1<<" :";
cin>>marks[i];
}
cout<<endl<<endl;
}
void compute(){
float s=0;
float avg;
for(int i=0;i<5;i++){
s+=marks[i];}

avg=s/5;
cout<<"\nsum of 5 mark : "<<s<<endl;
cout<<"averag for mark student : "<<avg<<endl;}

void tmax()
{
int max=marks[0];
for(int i=0;i<5;i++){
if(max<marks[i]) max=marks[i]; ;
}
cout<<"max marks of student : "<<max<<endl;

}
void display(){

cout<<"name student : "<<sname<<endl;


for(int i=0;i<5;i++){
cout<<"mark "<<i+1<<" :";
cout<<marks[i]<<endl;
}
compute();
tmax();
cout<<"\n\n";
}
};
int main()
{

student st[3];
for(int i=0;i<3;i++){
cout<<"enter information student "<<i+1<<" :\n";
st[i].assign();
}
cout<<"******************************************************\n";
for(int i=0;i<3;i++){
cout<<"information student "<<i+1<<" :\n";
st[i].display();
}
return 0;
}

You might also like