0% found this document useful (0 votes)
792 views12 pages

Journal Program (C++)

The document contains 7 programming problems related to C++ and object-oriented programming. The first problem demonstrates entering and printing student data. The second uses scope resolution operator. The third shows an inline function. The fourth overloads a sum function with different arguments. The fifth defines a Student class. The sixth uses static data members and member functions. The seventh creates an array of Movie objects.

Uploaded by

gobinath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
792 views12 pages

Journal Program (C++)

The document contains 7 programming problems related to C++ and object-oriented programming. The first problem demonstrates entering and printing student data. The second uses scope resolution operator. The third shows an inline function. The fourth overloads a sum function with different arguments. The fifth defines a Student class. The sixth uses static data members and member functions. The seventh creates an array of Movie objects.

Uploaded by

gobinath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

BCA-III C++ and Object Oriented Programming

JOURNAL PROGRAM LIST


SUBJECT: C++ and OOP

1. Write a program in C++ to enter the data of students (Name, CollegeName, Branch, Rollno,

Result) and print it on a screen.

#include<iostream.h>

main()
{

int rollno;
char name[10],branch[10],clg[15];
float result;

cout<<"--Enter the information of students--"<< endl;

cout<<"Enter Name: ";


cin>>name;
cout<<"Enter College: ";
cin>>clg;
cout<<"Enter Rollno: ";
cin>>rollno;
cout<<"Enter Branch: ";
cin>>branch;
cout<<"Enter Result: ";
cin>>result;

cout<<----------------------------------<< endl ;

cout<<"Name is :"<<name<< endl;


cout<<"College name is :"<<clg << endl;
cout<<"Rollno is: "<<rollno<< endl;
cout<<"Branch is: "<<branch << endl;
cout<<"Result is: "<<result;

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

Output:

--Enter the information of students


Enter Name: Ajay
Enter College: Christ
Enter Rollno: 001
Enter Branch: Computer
Enter Result: 67.76
-----------------------------------
Name is: Ajay
College Name is: Christ
Rollno is: 001
Branch is: Computer
Result is: 67.76

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

2. Write a program to demonstrate scope resolution operator.

#include<iostream.h>

int a=15; // global variable

main()
{

int a=10; // local vaiable

cout<<"Local Variable Value is: "<< a << endl ;


cout<<"Global Variable Value is: "<< ::a;

Output:

Local Variable Value is: 10


Global Variable Value is: 15

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

3. Write a program to demonstrate inline function.

#include<iostream.h>

inline int add(int x, int y)


{
int z ;
z = x + y ;
return z;
}
int main ()
{
int a , b ;

cout << "Enter the value of a:-" ;


cin >> a ;

cout << "Enter the value of b:-" ;


cin >> b ;

cout <<Addition is:= << add( a, b) ;

Output:

Enter the value of a:- 10


Enter the value of b:- 5
Addition is:= 15

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

4. Write a program to create function sum and overloaded the same function with different

types of arguments and different number of arguments.

#include<iostream.h>

int sum(int,int);
int sum(int,int,int);
float sum(int,float);
double sum(float,float);

main()
{

cout<< Answer is: <<sum(10,10) << endl;


cout<< Answer is: <<sum(10,20,30) << endl;
cout<< Answer is: <<sum(10,4.25f) <<endl;
cout<< Answer is: <<sum(4.25f,6.25f);

int sum(int x,int y)


{
return x + y;
}

int sum(int p,int q,int r)


{
return p + q + r;
}

float sum(int t,float u)


{
return t + u;
}

double sum(float i,float j)


{
return i + j;
}

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

Output:

Answer is: 20
Answer is: 60
Answer is: 14.25
Answer is: 10.5

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

5. Create a class Student that has rollno, name, marks of three subjects, total and percentage

as data members. Enter all the information of the student and calculate the total marks and

percentage inside the calculate function. Get all the information and print it on a screen

using appropriate member functions.

#include<iostream.h>
#include<conio.h>

class student
{
int rollno,m1,m2,m3,total;
char name[10];
float per;

public:
void getinfo()
{
cout<<"-:Enter Information and Marks of Student:-" <<endl;
cout<<endl ;

cout<<"-Enter Name and Rollno of the Students-";


cin>>name>>rollno;

cout<<"-Enter 3 subjects marks of the students-";


cin>>m1>>m2>>m3;

void calculate()
{
total = m1 + m2 + m3 ;

per = total / 3.0 ;


}

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

void showinfo()
{
cout<<"Name: "<<name << endl ;
cout<<"Rollno: "<<rollno << endl ;
cout<<"Marks: "<<m1<<","<<m2<<" and "<<m3 << endl ;
cout<<"Total is:"<<total<<" , "<<"Percentage is:"<<per;
}
};
main()
{
student s1;
s1.getinfo();
s1.calculate();
s1.showinfo();

Output:

-:Enter Information and Marks of Student:-

-Enter Name and Rollno of the Students-


Sachin
101

-Enter 3 subjects marks of the students-


66
68
67

Name: Sachin
Rollno: 101
Marks: 66 , 68 and 67
Total is:201
Percentage is: 67

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

6. Write a program to demonstrate static data member and member functions.

#include <iostream.h>
#include <conio.h>

class test
{
static int counter ; //static data member
public :
void getdata ()
{

counter++ ;
}

static void display ()//static member function


{
cout << "counter = " << counter << endl ;
}
};

int test :: counter ; //static member definition

main ()
{
test t1, t2 ;

t1.getdata () ;

t2.getdata () ;

test :: display () ; //using class name

t2.getdata () ;
t2.display () ; //using object name

output:
counter = 2
counter = 3

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

7. Create class Movie that has movie_name, actor, and actress as data members. Enter at list 5

movie data using creating array of object. Get and print the data on the screen using

appropriate member functions.

#include <iostream.h>
#include <conio.h>

class Movie
{
char m_name[20] ;
char actor[20] ;
char actress[20] ;

public :

void getmovie ()
{

cout << "Enter Movie name: " ;


cin >> m_name ;
cout << "Enter actor: " ;
cin >> actor ;
cout << "Enter actress: " ;
cin >> actress ;
cout<< endl ;

void display ()
{
cout <<"Movie Name is: " << m_name << endl;
cout <<"Actor of Movie is: " << actor << endl;
cout <<"Actress of Movie is: "<< actress<<endl;
cout<< endl ;
}

};

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

main ()
{
int i ;
Movie m[5] ; // create array of object

for (i=0; i<5; i++)


{
cout<<"Enter Details of Movie "<< i+1<<endl ;
m[i].getmovie () ;
}

cout << "-----Record of Movies-----"<< endl ;


for (i=0; i<5; i++)
{
cout << "Movie " << i+1 << endl ;
m[i].display () ;
}

getch () ;
}

output:
----Enter detail of Movie 1----
Enter Movie name : DDLJ
Enter Actor : ShahRukhKhan
Enter Actress : Kajol

----Enter detail of Movie 2----


Enter Movie name : RACE
Enter Actor : SaifAliKhan
Enter Actress : Dipika

----Enter detail of Movie 3----


Enter Movie name : BANGBANG
Enter Actor : HritikRoshan
Enter Actress : Katrina

----Enter detail of Movie 4----


Enter Movie name : KICK
Enter Actor : SalmanKhan
Enter Actress :Jacqueline

----Enter detail of Movie 5----

Prepared by | Hemang R. Chath


BCA-III C++ and Object Oriented Programming

Enter Movie name : P.K.


Enter Actor : AmirKhan
Enter Actress : Anushka

-----Records of Movies-----

Movie 1
Movie Name is: DDLJ
Actor of Movie is: ShahRukhKhan
Actress of Movie is: Kajol

Movie 2
Movie Name is: RACE
Actor of Movie is: SaifAliKhan
Actress of Movie is: Dipika

Movie 3
Movie Name is: BANGBANG
Actor of Movie is: HritikRoshan
Actress of Movie is: Katrina

Movie 4
Movie Name is: KICK
Actor of Movie is: SalmanKhan
Actress of Movie is: Jacqueline

Movie 5
Movie Name is: P.K.
Actor of Movie is: AmirKhan
Actress of Movie is: Anushka

Prepared by | Hemang R. Chath

You might also like