//Develop a C++ program to find the largest of three numbers
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"enter the value for a"<<endl;
cin>>a;
cout<<"enter the value for b"<<endl;
cin>>b;
cout<<"enter the value for c"<<endl;
cin>>c;
if(a>b && a>c)
{
cout<<"a is largest"<<endl;
}
else if(b>a && b>c)
{
cout<<"b is largest"<<endl;
}
else
{
cout<<"c is largest"<<endl;
}
return 0;
}
//Develop a C++ program using classes to display student name, roll number, marks
obtained in two subjects and total score of student
#include <iostream>
using namespace std;
class Student
{
char name[10];
int roolno,marks1,marks2,total;
public : void read();
void display();
void totalscore();
};
void Student :: read()
{
cout<<"Enter student name"<<endl;
cin>>name;
cout<<"Enter student rollno"<<endl;
cin>>roolno;
cout<<"Enter student marks1"<<endl;
cin>>marks1;
cout<<"Enter student marks2"<<endl;
cin>>marks2;
void Student :: totalscore()
{
total = marks1+marks2;
}
void Student :: display()
{
cout<<"Student name is"<<endl;
cout<<name<<endl;
cout<<"Student rollno is"<<endl;
cout<<roolno<<endl;
cout<<"Student marks1 is"<<endl;
cout<<marks1<<endl;
cout<<"Student marks2 is"<<endl;
cout<<marks2<<endl;
cout<<"Student total score is"<<endl;
cout<<total<<endl;
}
int main()
{
Student s1;
s1.read();
s1.totalscore();
s1.display();
return 0;
}
//Develop a C++ program to demonstrate function overloading for the following
prototypes.
• add(int a, int b)
• add(double a, double b)
#include <iostream>
using namespace std;
void add(int a, int b)
{
cout << "sum of " <<a<<" and " <<b<<" is = "<< (a + b)<<endl;
}
void add(double a, double b)
{
cout << "sum of " <<a<<" and " <<b<<" is = "<< (a + b)<<endl;
}
int main()
{
int a,b;
double p,q;
cout<<"enter values for a and b"<<endl;
cin>>a;
cin>>b;
add(a, b);
cout<<"----------------------------------"<<endl;
cout<<"enter values for p and q"<<endl;
cin>>p;
cin>>q;
add(p,q);
return 0;
}