OOP ASSIGNMENT - 1 - Coding is Funny

OOP ASSIGNMENT - 1




<!-- Ap: 1  -->

#include<iostram>
using namespace std;
int sum(int,int);
int main()
{
 int a,b;
 cout<<"enter the value of a:";
 cin>>a;
 cout<<"enter the value of b:";
 cin>>b;
 cout<<"sum="<<sum(a,b);
 return 0;
}
int sum(int a,int b)
{
 return (a+b);
}

<!-- Ap: 2 -->

#include<iostram>
using namespace std;
int fact(int);
int main()
{
 int a,c,fact;
 cout<<"enter the value of a:";
 cin>>a;
 c=fact(a);
 cout<<"the factorial is ="<<c;
 return 0;
}
int fact(int a)
{
 int f=1;
 for(int i=a;i>0;i--)
 {
  f=f*i;
 }
 return f;
}

<!-- Ap: 3 -->

#include<iostram>
using namespace std;
int prime(int,int);
int main()
{
 int a,b,fact;
 cout<<"enter the start value:";
 cin>>a;
 cout<<"enter the end value:";
 cin>>b;
 fact = prime(a,b);
 return 0;
}
int prime(int a,int b)
{
 int i,j,c;
 for(i=a;i<b;i++)
 {
  c=0;
  for(j=1;j<=i;j++)
  {
   if(i%j==0)
   {
    c++;
   }
  }
  if(c==2)
  {
   cout<<i<<",";
  }
 }
}

<!-- Ap:4  -->

#include<iostream>
using namespace std;
int main()
{
 int a,b,temp;
 int &c=a,&d=b;
 cout<<"enter value of a";
 cin>>a;
 cout<<"enter value of b";
 cin>>b;
 temp=c+d;
 cout<<"sum is="<<temp;
 return 0;
}

<!-- Ap:5 -->

#include<iostream>
using namespace std;
class batsman
{
 int bcode,innings,notout,runs;
 char bname[20];
 float batavg;
 public:
  void readdata();
  void calcavg();
  void display();
}o;
void batsman::readdata()
{
 cout<<"enter the bcode:";
 cin>>bcode;
 cout<<"enter the bname:";
 cin>>bname;
 cout<<"enter the number of innings:";
 cin>>innings;
 cout<<"enter the number of notout";
 cin>>notout;
 cout<<"enter the number of runs";
 cin>>runs;
}
void batsman::calcavg()
{
 batavg = runs(innings-notout);
 cout<<"\n\t batting avg:"<<batavg;
}
void batsman::display()
{

 cout<<"\n the bcode:"<<bcode;
 cout<<"\n the bname:"<<bname;
 cout<<"\n the number of innings:"<<innings;
 cout<<"\n the number of notout:"<<notout;
 cout<<"\n the number of runs:"<<runs;
 calcavg();
}
void main()
{
 o.readdata();
 o.display();
}

<!-- Ap:6 -->

#include<iostream.h>
using namespace std;
class book
{
 int b_no;
 char b_type[20];
 float b_price;
public :
 void get_data();
 void total_cost(int);
 void purchase();
};
void book :: get_data()
{
 cout<<"enter book no, book type and book price :\n";
 cin>>b_no>>b_type>>b_price;
}
void book :: total_cost(int n)
{
 int sum=0;
 sum=b_price*n;
 cout<<"\n total cost is : "<<sum;
}
void book :: purchase()
{
 int n;
 cout<<"\nenter the total book you purchase : ";
 cin>>n;
 total_cost(n);
}
int main()
{
 book b1;
 int n;
 clrscr();
 b1.get_data();
 cout<<"\nenter the total number of books : ";
 cin>>n;
 b1.total_cost(n);
 b1.purchase();
 getch();
 return 0;
}

<!-- Ap : 7 -->

#include<iostream>
using namespace std;
class report
{
 private:
  int no;
  char name[20];
  float m[5];
 public:
  void readinfo();
  void getavg();
  void display();
}o;
void report::readinfo()
{
 cout<<"enter the admin no:";
 cin>>no;
 cout<<"enter the bname:";
 cin>>name;
 cout<<"enter the number of marks:";
 for(i=0;i<5;i++)
 {
  cout<<"enter the marks of"<<i+1;
  cin>>m[i];
 }
}
void report::getavg()
{
 int sum=0;
 for(int i=0;i<5;i++)
 {
  sum=sum+m[i];
 }
 cout<<"marks avg"<<(sum/5);
} 
void report::display()
{
 cout<<"\n enter the admin no"<<no;
 cout<<"\n enter the name"<<name;
 cout<<"\n number of marks";
 for(i=0;i<5;i++)
 {
  cout<<"\t"<<m[i];
 }
 getavg();
}
void main()
{
 o.readinfo();
 o.display();
}

<!-- AP-8 -->

#include<iostream>
using namespace std;
class student
{
 private:
  int admno;
  char sname[20];
  float eng,math,science;
 public:
  void readdata();
  void ctotal();
  void showdata();
}o;
void student::readdata()
{
 cout<<"enter the Roll no:";
 cin>>admno;
 cout<<"enter the sname:";
 cin>>sname;
 cout<<"enter the marks of eng :";
 cin>>eng;
 cout<<"enter the marks of math :";
 cin>>math;
 cout<<"enter the marks of science :";
 cin>>science;
}
void student::ctotal()
{
 int sum=0;
 sum=eng+math+science;
 
 cout<<"marks avg"<<(sum/3);
} 
void student::showdata()
{
 cout<<"\nthe Roll no"<<admno;
 cout<<"\nthe sname"<<sname;
 cout<<"\nthe marks of eng :"<<eng;
 cout<<"\nthe marks of math :"<<math;
 cout<<"\nthe marks of science :"<<science;
 ctotal();
}
void main()
{
 o.readdata();
 o.showdata();
}


<!-- AP-09 -->

#include<iostream>
using namespace std;
class student
{
 public:
  void area(int );
  void area(int ,int ,int );
  void area(float ,float );
}o;
void student::area(int l)
{
 cout<<"\n area of square"<<l*l;
}
void student::area(int l,int b,int h)
{
 cout<<"\n area of rectangle"<<l*b*h;
}
void student::area(float r,float pi=3.14)
{
 cout<<"\n area of circle"<<pi*r*r;
}
void main()
{
 o.area(5);
 o.area(5,6,7);
 o.area(3.7,3.14);
}


<!-- AP-10 -->

#include<iostream>
using namespace std;
class item
{
 int itemno;
 char iname[20];
 public:
  inline void takedata();
  inline void showdata();
}o;
inline void item::takedata()
{
 cout<<"Enter the item no : ";
 cin>>itemno;
 cout<<"Enter the item name : ";
 cin>>iname;
}
inline void item::showdata()
{
 cout<<"\nThe item no : "<<itemno;
 cout<<"\nThe item name : "<<iname;
}
void main()
{
 o.takedata();
 o.showdata();
}

  • Share: