AP LAB 3
1) #include <bits/stdc++.h>
using namespace std;
class student
public:
int age;
int roll_no;
};
int main(){
student S1;
S1.age=21;
S1.roll_no=2;
cout<<S1.age<<" "<<S1.roll_no<<endl;
Output: 21 2
2) #include <bits/stdc++.h>
using namespace std;
class student
public:
int roll_no;
int m1;
int m2;
int m3;
void print_sum(){
cout<<"Sum of all marks is "<<m1+m2+m3<<endl;
void print_avg(){
cout<<"average of 3 subjects is "<<(m1+m2+m3)/3<<endl;
};
int main(){
student S1;
S1.m1=21;
S1.m2=2;
S1.m3=19;
S1.print_sum();
S1.print_avg();
Output Sum of all marks is 42
average of 3 subjects is 14
3) #include <bits/stdc++.h>
using namespace std;
class traingle
int s1;
int s2;
int s3;
public:
void getdata(int a,int b,int c){
s1=a;
s2=b;
s3=c;
void print_peri(){
cout<<"perimeter of triangle is "<<s1+s2+s3<<endl;
void print_area(){
int s=(s1+s2+s3)/2;
int area=sqrt((s)*(s-s1)*(s-s2)*(s-s3));
cout<<"area of traingle is "<<area<<endl;
};
int main(){
traingle T1;
T1.getdata(3,4,5);
T1.print_peri();
T1.print_area();
}
Output perimeter of triangle is 12 area of traingle is 6
4) #include <bits/stdc++.h>
using namespace std;
class EMPLOYEE{
int empcode;
string empname;
float package;
public:
void getdata(int a, string s, float b ){
empcode =a;
empname=s;
package =b;
void display(){
cout << "Employee code is "<<empcode<<endl;
cout << "Employee name is "<<empname<<endl;
cout << "Employee salary is "<<package<<endl;
};
int main(){
int n;
cout<< "enter number of employees"<<endl;
cin>> n;
int a;
string s;
float b;
EMPLOYEE emp[n];
for (int i =0;i<n;i++){
cout<< "enter code of "<<i+1<<"employee"<<endl;
cin>> a;
cout<< "enter name of "<<i+1<<"employee"<<endl;
cin>> s;
cout<< "enter package of "<<i+1<<"employee"<<endl;
cin>> b;
emp[i].getdata(a,s,b);
for (int j=0;j<n;j++){
emp[j].display();
Output
enter number of employees
enter code of 1employee
enter name of 1employee
enter package of 1employee
123
enter code of 2employee
enter name of 2employee
enter package of 2employee
456
Employee code is 1
Employee name is a
Employee salary is 123
Employee code is 2
Employee name is b
Employee salary is 456
5)
6) #include<bits/stdc++.h>
using namespace std;
class accounts{
int accno;
string name;
int balance;
public:
void getdata(int a,string s,int b){
accno=a;
name=s;
balance=b;
void deposit(int a){
balance=balance+a;
void withdraw(int a){
if(balance<a){
cout<<"balance is low"<<endl;
}
else{
balance=balance-a;
void display(){
cout<<"account number: "<<accno<<endl;
cout<<"account holder name: "<<name<<endl;
cout<<"balance: "<<balance<<endl;
};
int main(){
accounts A1;
A1.getdata(1,"first",1000);
A1.deposit(500);
A1.withdraw(750);
A1.display();
A1.withdraw(2000);
Output
account number: 1
account holder name: first
balance: 750
balance is low