0% found this document useful (0 votes)
39 views

Cs 12

The document contains 3 code examples demonstrating: 1) A recursive function to calculate the factorial of a number. 2) A program to reverse a string using the strrev() function. 3) A customer class with private data members for customer details and public member functions to input and output customer data.

Uploaded by

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

Cs 12

The document contains 3 code examples demonstrating: 1) A recursive function to calculate the factorial of a number. 2) A program to reverse a string using the strrev() function. 3) A customer class with private data members for customer details and public member functions to input and output customer data.

Uploaded by

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

PRACTICAL 1...

/* Display the factorial of the entered number using Function Recursion*/

#include<iostream.h>
long facto(int a);
void main()
{
int a;
long b;
cout<<"Enter a number: ";
cin>>a;
cout<<endl;
b=facto(a);
cout<<a<<"! = "<<b;
}
long facto(int a)
{
if (a==0)
return 1;
else
return (a*facto(a-1));

}
OUTPUT... 1
PRACTICAL 2...

/* A program to print the reverse of the entered String*/

#include<iostream.h>
#include<stdio.h>
#include<string.h>
void main()
{
char AB[50];
cout<<"Enter the string: \n";
gets(AB);
strrev(AB);
cout<<"\n\n The 'REVERSE' of the given string is: \n";
puts(AB);
}
OUTPUT 2
PRACTICAL 3...

/* Write a program to display a costumer class with the following


specifications:

Private members:

c_name 25 characters
address 25 characters
city 15 characters
state 2 characters
balance double

Public Members:

void input_data To enter the costumer class attributes


void output_data To print the costumer class attributes*/

#include<iostream.h>
#include<stdio.h>
class costumer
{
char c_name[25],address[25],city[15],state[2];
double balance;

public:

void input_data()
{
cout<<"Enter the name of the costumer: ";
gets(c_name);
cout<<"\nEnter the Address: ";
gets(address);
cout<<"\nEnter the city of the costumer: ";
gets(city);
cout<<"\nEnter the state of the costumer: ";
gets(state);
cout<<"\nEnter the amount: ";
cin>>balance;
}
void output_data()
{
puts(c_name);
puts(address);
puts(city);
puts(state);
cout<<balance;
}
};
void main()
{
costumer cls;
cls.input_data();
cout<<"\n\n\n";
cls.output_data();
}
OUTPUT 3

You might also like