This didn\'t work and compile with me, I need to add more things. using c++, ple
ID: 3682487 • Letter: T
Question
This didn't work and compile with me, I need to add more things. using c++, please complete the following: program "object" class student display average of 3 scoers.
#include <iostream>
#include <iomanip>
using namespace std;
class student
{
private:
int score1,
score2,
score3;
public:
student();
student(int, int, int);
void setScore1(int);
void setScore2(int);
void setScore3(int);
int getScore1();
int getScore2();
int getScore3();
double calcAvg();
};
student::student()
{
score1=0;
score2=0;
score3=0;
}
student::student(int sc1, sc2, sc3)
{
score1=sc1;
score2=sc2;
score3=sc3;
}
void student::setScore1(int sc1)
{
score1=sc1;
}
void student::setScore2(int sc2)
{
score2=sc2;
}
void student::setScore3(int sc3)
{
score3=sc3;
}
double calcAvg::getAvg()
{
return sc1+sc2+sc3/3.0;
}
int main()
{
int sc1, sc2, sc3, avg;
student A;
cout<<"enter quiz 1:";
cin>>sc1;
cout<<"enter quiz 2:";
cin>>sc2;
cout<<"enter quiz 3:";
cin>>sc3;
avg=(sc1+sc2+sc3/3.0);
cout<<"average is:"<<avg<<endl;
}
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#define SIZE 10
class emp
{
float m1,m2,m3;
char name[20],num[10];
public:
void getdata();
void dispdata();
};
void emp::getdata()
{
cout<<" Enter student USN: " ;
cin>>name;
cout<<"Enter student name: " ;
cin>>num;
cout<<"Enter student's 3 marks: " ;
cin>>m1>>m2>>m3;
}
void emp::dispdata()
{
float avg,low=m3;
if(m2<low)
low=m2;
else if(m3<low)
low=m3;
avg=(m1+m2+m3-low)/2;
cout<<" student USN: "<<name
<<" student name: "<<num
<<" student average: "<<avg;
}
void main()
{
clrscr();
emp ob[SIZE];
int n;
cout<<" ";
cout<<" *******************************"
<<" Students Report"
<<" *******************************"
<<" Enter the number of students: ";
cin>>n;
for(int i=0;i<n;i++)
{
ob[i].getdata();
}
clrscr();
cout<<" -----------------"
<<" students Details::"
<<" -----------------";
for( i=0;i<n;i++)
{
cout<<" student:"<<i+1
<<" ----------";
ob[i].dispdata();
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.