Journal Program (C++)
Journal Program (C++)
1. Write a program in C++ to enter the data of students (Name, CollegeName, Branch, Rollno,
#include<iostream.h>
main()
{
int rollno;
char name[10],branch[10],clg[15];
float result;
cout<<----------------------------------<< endl ;
Output:
#include<iostream.h>
main()
{
Output:
#include<iostream.h>
Output:
4. Write a program to create function sum and overloaded the same function with different
#include<iostream.h>
int sum(int,int);
int sum(int,int,int);
float sum(int,float);
double sum(float,float);
main()
{
Output:
Answer is: 20
Answer is: 60
Answer is: 14.25
Answer is: 10.5
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
#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 ;
void calculate()
{
total = m1 + m2 + m3 ;
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:
Name: Sachin
Rollno: 101
Marks: 66 , 68 and 67
Total is:201
Percentage is: 67
#include <iostream.h>
#include <conio.h>
class test
{
static int counter ; //static data member
public :
void getdata ()
{
counter++ ;
}
main ()
{
test t1, t2 ;
t1.getdata () ;
t2.getdata () ;
t2.getdata () ;
t2.display () ; //using object name
output:
counter = 2
counter = 3
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
#include <iostream.h>
#include <conio.h>
class Movie
{
char m_name[20] ;
char actor[20] ;
char actress[20] ;
public :
void getmovie ()
{
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 ;
}
};
main ()
{
int i ;
Movie m[5] ; // create array of object
getch () ;
}
output:
----Enter detail of Movie 1----
Enter Movie name : DDLJ
Enter Actor : ShahRukhKhan
Enter Actress : Kajol
-----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