Professional Documents
Culture Documents
C Termsem2
C Termsem2
Course : BSC.IT
Name : Ansh Gujral
Roll No: 09
UNI Roll No: 2200709
Subject: C++ lab
Submitted to:
Mrs. Vandana Rawat Maam
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
Q1.Write a program in c++ for sum of two numbers and cube using inline
function.
OBJECTIVE: To learn the concept of Inline function.
#include<iostream>
using namespace std;
class ansh // class name
{
public: //access specifier
inline void cube(int a) //inline function
{
int cube =a*a*a; // Ansh Gujral
cout<< " cube is: "<<cube;
}
inline void sum(int a,int b)
{
int add=a+b;
cout<<"addition: "<<add;
}
};
int main() //main function
{
int a;
int b;
cout<<"enter the numbers:";
cin>>a>>b;
ansh s; //object calling
s.sum(a,b);
s.cube(a);}
C++ LAB
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
Output:
enter the numbers:5 8
addition: 13 cube is: 125
Press any key to continue . . .
C++ LAB
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
C++ LAB
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
Output:
the global variable is:151
the local variable is: 62
Press any key to continue . . .
C++ LAB
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
Q3.Write a program in c++ to get detail of students and print the details by
creating object.
OBJECTIVE: To learn the concept of c++.
#include<iostream>
using namespace std;
class student //class name
{
public: //access specifier
char stu_name[12];
int roll_no;
char course_name[20];
long long ph_no;
void get_details() //member function
{
cout<<"enter the student name:";
cin>>stu_name;
cout<<"enter the roll no of students:";
cin>>roll_no;
cout <<"enter the course name:";
cin>>course_name;
cout<<"enter the student's phone number:";
cin>>ph_no;
}
void put_details() //member function
{
cout<<" The student details are:- \n";
cout<<"\n *************";
cout<<" \nThe student name is :"<<stu_name;
C++ LAB
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
C++ LAB
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
Output:
The student details are:-
*************
The student name is :ansh
The student roll no is :2200709
The student's course is :BscIT
The student's phone number is :8979754244
Press any key to continue . . .
C++ LAB
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
#include <iostream>
using namespace std;
class Parent
{
static int n1;
public:
static int n2;
// The class member can be accessed using the scope resolution operator.
void fun1 ( int n1)
{
// n1 is accessed by the scope resolution operator (:: )
cout << " The value of the static integer n1: " << Parent::n1;
cout << " \n The value of the local variable n1: " << n1;
}
};
// define a static member explicitly using :: operator
int Parent::n1 = 5; // declare the value of the variable n1
int Parent::n2 = 10;
int main ()
{
Parent b;
int n1 = 15;
b.fun1 (n1);
cout << " \n The value of the Base::n2 = " << Parent::n2;
return 0;
}
C++ LAB
Name: Ansh Gujral------Roll no.09------Uni.Roll No:2200709------BSc.IT. ------Sem2------
Output:
The value of the static integer n1: 5
The value of the local variable n1: 15
The value of the Base::n2 = 10
C++ LAB