Showing posts with label Codes. Show all posts
Showing posts with label Codes. Show all posts
Sunday, 12 June 2016
Thursday, 9 June 2016
Library Management system (LMS) using File Handling and Login form without graphics
Before running the code do not forget to create two .txt type files of name "pass" and "user" save the password in the pass file and username in the user file. Then enter the username and password which you saved in the "pass" and "user" files. Only then you will be able to access the library management system.
Tuesday, 31 May 2016
ATM Machine using Simple Switch cases .exe file and Source Code
TO DOWNLOAD THE .exe FILE and TEST THE PROGRAM CLICK HERE...
TO DOWNLOAD THE SOURCE CODE OF THE PROJECT CLICK HERE...
TO DOWNLOAD THE SOURCE CODE OF THE PROJECT CLICK HERE...
Tuesday, 26 April 2016
Copy one string into another string. Remeber string is an 'char' type array.
#include <iostream>
#include <stdio.h>
using namespace std;
void strcpy(char [],char []);
int main()
{
char array1[2000],array2[2000];
cout<<"Enter Your Statement : "<<endl;
gets(array1);
cout<<"After Copying the First Statement into The Second the Second Statement Becomes : "<<endl;
strcpy(array1,array2);
return 0;
}
void strcpy(char array1[],char array2[])
{
int i=0;
while(array1[i]!='\0')
{
array2[i]=array1[i];
i++;
}
array2[i]='\0';
cout<<array2;
}
#include <stdio.h>
using namespace std;
void strcpy(char [],char []);
int main()
{
char array1[2000],array2[2000];
cout<<"Enter Your Statement : "<<endl;
gets(array1);
cout<<"After Copying the First Statement into The Second the Second Statement Becomes : "<<endl;
strcpy(array1,array2);
return 0;
}
void strcpy(char array1[],char array2[])
{
int i=0;
while(array1[i]!='\0')
{
array2[i]=array1[i];
i++;
}
array2[i]='\0';
cout<<array2;
}
String.h Library function STRUPR
This function converts the lower case string or statement into upper case statement.
#include <iostream>
#include <stdio.h>
using namespace std;
void strupr(char []);
int main()
{
char arr[2000];
cout<<"Enter the statement : "<<endl;
gets(arr);
cout<<"After converting small case letter letters into uppercase letters : "<<endl;
strupr(arr);
cout<<arr;
return 0;
}
void strupr(char array[])
{
int i=0;
while(array[i]!='\0')
{
if(array[i]>='a' && array[i]<='z')
{
array[i]=array[i]-32;
}
i++;
}
}
#include <iostream>
#include <stdio.h>
using namespace std;
void strupr(char []);
int main()
{
char arr[2000];
cout<<"Enter the statement : "<<endl;
gets(arr);
cout<<"After converting small case letter letters into uppercase letters : "<<endl;
strupr(arr);
cout<<arr;
return 0;
}
void strupr(char array[])
{
int i=0;
while(array[i]!='\0')
{
if(array[i]>='a' && array[i]<='z')
{
array[i]=array[i]-32;
}
i++;
}
}
Transpose of a Matrix using C++
#include <iostream>
using namespace std;
int main()
{
int array[3][3],trans[3][3],i,j;
for(i=0; i<3; ++i)
for(j=0; j<3; ++j)
{
cout << "Enter elements a" << i+1 << j+1 << ": ";
cin >> array[i][j];
}
cout << endl << "Entered Matrix: " << endl;
for(i=0; i<3; ++i)
for(j=0; j<3; ++j)
{
cout << " " << array[i][j];
if(j==3-1)
cout << endl << endl;
}
for(i=0; i<3; ++i)
for(j=0; j<3; ++j)
{
trans[j][i]=array[i][j];
}
cout << endl << "Transpose of Matrix: " << endl;
for(i=0; i<3; ++i)
for(j=0; j<3; ++j)
{
cout << " " << trans[i][j];
if(j==3-1)
cout << endl << endl;
}
return 0;
}
using namespace std;
int main()
{
int array[3][3],trans[3][3],i,j;
for(i=0; i<3; ++i)
for(j=0; j<3; ++j)
{
cout << "Enter elements a" << i+1 << j+1 << ": ";
cin >> array[i][j];
}
cout << endl << "Entered Matrix: " << endl;
for(i=0; i<3; ++i)
for(j=0; j<3; ++j)
{
cout << " " << array[i][j];
if(j==3-1)
cout << endl << endl;
}
for(i=0; i<3; ++i)
for(j=0; j<3; ++j)
{
trans[j][i]=array[i][j];
}
cout << endl << "Transpose of Matrix: " << endl;
for(i=0; i<3; ++i)
for(j=0; j<3; ++j)
{
cout << " " << trans[i][j];
if(j==3-1)
cout << endl << endl;
}
return 0;
}
Tuesday, 5 April 2016
Stirng.h Library Function strtok convert a string into tokens.(How do this program works.?)
STRTOK:
This function inputs an array from user and convert the given string into tokens or you can say convert every complete word into a different line.
#include <stdio.h>
using namespace std;
void strtok(char []);
int main()
{
char arr[200];
cout << "Enter the statement : " << endl;
gets(arr);
cout<<"After Converting statement into tokens: "<<endl;
strtok(arr);
return 0;
}
void strtok(char array[])
{
int i=0;
while(array[i]!='\0')
{
if(array[i]==' ')
{
cout<<endl;
}
else if(array[i]!='\0')
{
cout<<array[i];
}
i++;
}
}
This function inputs an array from user and convert the given string into tokens or you can say convert every complete word into a different line.
Here is the Code for this Program.>>>
#include <iostream>#include <stdio.h>
using namespace std;
void strtok(char []);
int main()
{
char arr[200];
cout << "Enter the statement : " << endl;
gets(arr);
cout<<"After Converting statement into tokens: "<<endl;
strtok(arr);
return 0;
}
void strtok(char array[])
{
int i=0;
while(array[i]!='\0')
{
if(array[i]==' ')
{
cout<<endl;
}
else if(array[i]!='\0')
{
cout<<array[i];
}
i++;
}
}
Sunday, 3 April 2016
String.h Library strpbrk (How strpbrk works ? )
STPBRK : This function takes an array(string) of alphabets input from user and if user enters any number other than ABC alphabets it should display those integers or characters.
#include <stdio.h>
using namespace std;
void strpbrk(char []);
int main()
{
char arr[200];
cout<<"Enter the statement : "<<endl;
gets(arr);
strpbrk(arr);
return 0;
}
void strpbrk(char array[])
{
int i=0;
while(array[i]!='\0')
{
if(array[i]>='a' && array[i]<='z'){}
else if(array[i]>='A' && array[i]<='Z'){}
else {
cout<<array[i];
}
i++;
}
}
Here is the code : >>
#include <iostream>#include <stdio.h>
using namespace std;
void strpbrk(char []);
int main()
{
char arr[200];
cout<<"Enter the statement : "<<endl;
gets(arr);
strpbrk(arr);
return 0;
}
void strpbrk(char array[])
{
int i=0;
while(array[i]!='\0')
{
if(array[i]>='a' && array[i]<='z'){}
else if(array[i]>='A' && array[i]<='Z'){}
else {
cout<<array[i];
}
i++;
}
}
Saturday, 2 April 2016
String.h Library Function strrev (How to reverse a string without using strrev)
STRREV :
This funcion inputs an array(string) from user and outputs its reverse order.
#include <stdio.h>
using namespace std;
void strrev(char []);
int strlen(char []);
int main()
{
char arr[200];
cout<<"Enter any statement to get its reverse. "<<endl;
gets(arr);
cout<<"After Being reversed : "<<endl;
strrev(arr);
return 0;
}
void strrev(char array[])
{
int length,i;
length = strlen(array)-1;
char array1[length];
for(i=0 ; array[i]!='\0' ; i++)
{
array1[length]=array[i];
length--;
}
array1[length]='\0';
cout<<array1;
}
int strlen(char array[])
{
int sum=0;
for(int i=0 ; array[i]!='\0' ; i++)
{
sum+=1;
}
return sum;
}
This funcion inputs an array(string) from user and outputs its reverse order.
Here is the Code: >>>
#include <iostream>#include <stdio.h>
using namespace std;
void strrev(char []);
int strlen(char []);
int main()
{
char arr[200];
cout<<"Enter any statement to get its reverse. "<<endl;
gets(arr);
cout<<"After Being reversed : "<<endl;
strrev(arr);
return 0;
}
void strrev(char array[])
{
int length,i;
length = strlen(array)-1;
char array1[length];
for(i=0 ; array[i]!='\0' ; i++)
{
array1[length]=array[i];
length--;
}
array1[length]='\0';
cout<<array1;
}
int strlen(char array[])
{
int sum=0;
for(int i=0 ; array[i]!='\0' ; i++)
{
sum+=1;
}
return sum;
}
String.h Library Function strcat how strcat works
STRCAT : This function takes two strings from user and concatenates the second one with the first here is the code how strcat works :
And Here Is the Code : >>>
#include <iostream>
#include <stdio.h>
using namespace std;
void strcat(char [],char [],char []);
int main()
{
char arr[2000],arr1[2000],arr3[2000];
cout<<"Enter Your First Statement : "<<endl;
gets(arr);
cout<<"Enter Your second Statement : "<<endl;
gets(arr1);
cout<<"After Concatenating : "<<endl;
strcat(arr,arr1,arr3);
return 0;
}
void strcat(char array1[],char array2[],char array3[])
{
int i=0,j=0;
while(array1[i]!='\0')
{
array3[i] = array1[i];
i++;
}
array3[i] = ' ';
i++;
while(array2[j] != '\0')
{
array3[i] = array2[j];
i++;
j++;
}
array3[i] = '\0';
cout << array3;
}
Wednesday, 2 March 2016
Take a String input From User and Replace The Alphabets Given by User
SAMPLE OUTPUT :
CODE:
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
char str[50],f,r;
cout<<"Enter the Sentence of Maximum 50 Words : "<<endl;
gets(str);
cout<<"Enter the word Which you Want To Replace : "<<endl;
cin>>f;
cout<<"\nEnter The Word You Want to Replace with : "<<endl;
cin>>r;
for(int i=0 ; str[i]!='\0' ; i++)
{
if(str[i]==f)
{
str[i]=r;
}
}
cout<<str;
return 0;
}
How to Find the Largest Number in the User Defined Number Using 1-D array in C++
#include <iostream>
using namespace std;
int main()
{
int size,i;
int arrayname[size];
cout<<"Enter The number Of values."<<endl;
cin>>arrayname[size];
cout<<"Enter The Values : "<<endl;
for(i=0 ; i<size ; i++)
{
cin>>arrayname[i];
}
int max=arrayname[0];
for(i=0 ; i<size ; i++){
if(max<arrayname[i]){
max=arrayname[i];}
}
cout << "Maximum Number is : " <<max<< endl;
return 0;
}
using namespace std;
int main()
{
int size,i;
int arrayname[size];
cout<<"Enter The number Of values."<<endl;
cin>>arrayname[size];
cout<<"Enter The Values : "<<endl;
for(i=0 ; i<size ; i++)
{
cin>>arrayname[i];
}
int max=arrayname[0];
for(i=0 ; i<size ; i++){
if(max<arrayname[i]){
max=arrayname[i];}
}
cout << "Maximum Number is : " <<max<< endl;
return 0;
}
Thursday, 25 February 2016
By using ‘stuctures’ write a complete C++ program to compute the income tax of an employee. Your structure may have the following entries, By using ‘stuctures’ write a complete C++ program to compute the income tax of an employee. Your structure may have the following entries,By using ‘stuctures’ write a complete C++ program to compute the income tax of an employee.
#include <iostream>
using namespace std;
struct employee{
int emp_Id;
char empName[11];
char empdeptName[15];
double monthly_salary;
double yearly_sal, yearly_Tax, monthly_Tax;
void setSalary()
{
cout << "Enter your monthly salary : ";
cin >> monthly_salary;
getSalary();
/*
if(monthly_salary > 0 && monthly_salary < 80000)
{
getSalary();
}
else
{
exit();
}*/
}
void getSalary()
{
system("cls");
cout << "Your monthly salary is : " << monthly_salary << endl;
yearly_sal = monthly_salary * 12;
cout << "Your annual salary is : " << yearly_sal << endl;
yearly_Tax = yearly_sal * 7 / 100;
cout << "Your annual tax at the rate of 7 % is : " << yearly_Tax << endl;
cout << "Your monthly tax is : " << compute_Monthly_Tax() << endl;
}
void showSalaryOriginal()
{
cout << "Your monthly salary is : " << monthly_salary << endl;
cout << "Your annual salary is : " << yearly_sal<< endl;
}
void ShowSalaryAfterTax()
{
cout << "Your monthly salary after tax is : " << monthly_salary - monthly_Tax << endl;
cout << "Your annual salary after tax is : " << yearly_sal - yearly_Tax << endl;
}
double compute_Monthly_Tax()//Function will compute monthly tax
{
monthly_Tax = yearly_Tax / 12;
return monthly_Tax;
}
void exit()
{
cout << "End!!";
}
};
int main()
{
//Declaring variable of employee struct
employee emp;
cout << "Enter employee name : ";
cin.getline(emp.empName, 11);
cout << "Enter employee id : ";
cin >> emp.emp_Id;
emp.setSalary();
emp.showSalaryOriginal();
emp.ShowSalaryAfterTax();
system("pause");
return 0;
}
using namespace std;
struct employee{
int emp_Id;
char empName[11];
char empdeptName[15];
double monthly_salary;
double yearly_sal, yearly_Tax, monthly_Tax;
void setSalary()
{
cout << "Enter your monthly salary : ";
cin >> monthly_salary;
getSalary();
/*
if(monthly_salary > 0 && monthly_salary < 80000)
{
getSalary();
}
else
{
exit();
}*/
}
void getSalary()
{
system("cls");
cout << "Your monthly salary is : " << monthly_salary << endl;
yearly_sal = monthly_salary * 12;
cout << "Your annual salary is : " << yearly_sal << endl;
yearly_Tax = yearly_sal * 7 / 100;
cout << "Your annual tax at the rate of 7 % is : " << yearly_Tax << endl;
cout << "Your monthly tax is : " << compute_Monthly_Tax() << endl;
}
void showSalaryOriginal()
{
cout << "Your monthly salary is : " << monthly_salary << endl;
cout << "Your annual salary is : " << yearly_sal<< endl;
}
void ShowSalaryAfterTax()
{
cout << "Your monthly salary after tax is : " << monthly_salary - monthly_Tax << endl;
cout << "Your annual salary after tax is : " << yearly_sal - yearly_Tax << endl;
}
double compute_Monthly_Tax()//Function will compute monthly tax
{
monthly_Tax = yearly_Tax / 12;
return monthly_Tax;
}
void exit()
{
cout << "End!!";
}
};
int main()
{
//Declaring variable of employee struct
employee emp;
cout << "Enter employee name : ";
cin.getline(emp.empName, 11);
cout << "Enter employee id : ";
cin >> emp.emp_Id;
emp.setSalary();
emp.showSalaryOriginal();
emp.ShowSalaryAfterTax();
system("pause");
return 0;
}
By using function overloading write a complete C++ program that can compute the GPA of a student’s registering with different number of courses.
#include <iostream>
using namespace std;
void cal(char a,char b, char c,char d)
{
char ab[]={a,b,c,d};
int gp=0;
for(int i=0;i<4;i++)
{
if(ab[i]=='A')
{
gp=gp+4;
}
if(ab[i]=='B')
{
gp=gp+3;
}
if(ab[i]=='C')
{
gp=gp+2;
}
if(ab[i]=='D')
{
gp=gp+1;
}
if(ab[i]=='F')
{
gp=gp+0;
}
}
cout<<"GPA IS "<<gp;
}
void cal(char a,char b, char c,char d, char e)
{
char ab[]={a,b,c,d,e};
int gp=0;
for(int i=0;i<5;i++)
{
if(ab[i]=='A')
{
gp=gp+4;
}
if(ab[i]=='B')
{
gp=gp+3;
}
if(ab[i]=='C')
{
gp=gp+2;
}
if(ab[i]=='D')
{
gp=gp+1;
}
if(ab[i]=='F')
{
gp=gp+0;
}
}
cout<<"GPA IS "<<gp;
}
}
int main() {
int choice,temp=0;
char a[5];
for (int i=0;i<5;i++)
{
cout<<"enter course no "<< i+1 << "grade from A to D";
cin>>a[i];
temp++;
if(i>2)
{
cout<<"enter 1 if you do not want to enter marks anymore";
cin>>choice;
}
if(choice==1)
{
i=10;
}
}
switch(temp)
{
case 4:
{
cal(a[0],a[1],a[2],a[3]);
break;
}
case 5:
{
cal(a[0],a[1],a[2],a[3],a[4]);
break;
}
}
return 0;
}
Find factorial of a number using recursion in c program
#include<stdio.h>
int main(){
int num,f;
printf("\nEnter a number: ");
scanf("%d",&num);
f=fact(num);
printf("\nFactorial of %d is: %d",num,f);
return 0;
}
int fact(int n)
{
if(n==1)
return 1;
else
return(n*fact(n-1));
}
int main(){
int num,f;
printf("\nEnter a number: ");
scanf("%d",&num);
f=fact(num);
printf("\nFactorial of %d is: %d",num,f);
return 0;
}
int fact(int n)
{
if(n==1)
return 1;
else
return(n*fact(n-1));
}
Create a file and store data in it in c program
#include<stdio.h>
int main(){
FILE *fp;
char ch;
fp=fopen("file.txt","w");
printf("\nEnter data to be stored in to the file:");
while((ch=getchar())!=EOF) putc(ch,fp);
fclose(fp);
return 0;
}
int main(){
FILE *fp;
char ch;
fp=fopen("file.txt","w");
printf("\nEnter data to be stored in to the file:");
while((ch=getchar())!=EOF) putc(ch,fp);
fclose(fp);
return 0;
}
Multiplication of two matrices using c program
#include<stdio.h>
int main(){
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
printf("\nEnter the row and column of first matrix");
scanf("%d %d",&m,&n);
printf("\nEnter the row and column of second matrix");
scanf("%d %d",&o,&p);
if(n!=o){
printf("Matrix multiplication is not possible");
printf("\nColumn of first matrix must be same as row of second matrix");
}
else{
printf("\nEnter the First matrix->");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the Second matrix->");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
printf("\nThe First matrix is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<n;j++){
printf("%d\t",a[i][j]);
}
}
printf("\nThe Second matrix is\n");
for(i=0;i<o;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",b[i][j]);
}
}
for(i=0;i<m;i++)
for(j=0;j<p;j++)
c[i][j]=0;
for(i=0;i<m;i++){
//row of first matrix
for(j=0;j<p;j++){
//column of second matrix
sum=0;
for(k=0;k<n;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
}
printf("\nThe multiplication of two matrix is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",c[i][j]);
}
}
return 0;
}
int main(){
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
printf("\nEnter the row and column of first matrix");
scanf("%d %d",&m,&n);
printf("\nEnter the row and column of second matrix");
scanf("%d %d",&o,&p);
if(n!=o){
printf("Matrix multiplication is not possible");
printf("\nColumn of first matrix must be same as row of second matrix");
}
else{
printf("\nEnter the First matrix->");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the Second matrix->");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
printf("\nThe First matrix is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<n;j++){
printf("%d\t",a[i][j]);
}
}
printf("\nThe Second matrix is\n");
for(i=0;i<o;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",b[i][j]);
}
}
for(i=0;i<m;i++)
for(j=0;j<p;j++)
c[i][j]=0;
for(i=0;i<m;i++){
//row of first matrix
for(j=0;j<p;j++){
//column of second matrix
sum=0;
for(k=0;k<n;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
}
printf("\nThe multiplication of two matrix is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",c[i][j]);
}
}
return 0;
}
Program to convert decimal to binary in c
#include<stdio.h>
int main(){
long int decimalNumber,remainder,quotient;
int binaryNumber[100],i=1,j;
printf("Enter any decimal number: ");
scanf("%ld",&decimalNumber);
quotient = decimalNumber;
while(quotient!=0){
binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
}
printf("Equivalent binary value of decimal number %d: ",decimalNumber);
for(j = i -1 ;j> 0;j--)
printf("%d",binaryNumber[j]);
return 0;
}
int main(){
long int decimalNumber,remainder,quotient;
int binaryNumber[100],i=1,j;
printf("Enter any decimal number: ");
scanf("%ld",&decimalNumber);
quotient = decimalNumber;
while(quotient!=0){
binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
}
printf("Equivalent binary value of decimal number %d: ",decimalNumber);
for(j = i -1 ;j> 0;j--)
printf("%d",binaryNumber[j]);
return 0;
}
Write a c program to find out L.C.M. of two numbers.
#include<stdio.h>
int main(){
int n1,n2,x,y;
printf("\nEnter two numbers:");
scanf("%d %d",&n1,&n2);
x=n1,y=n2;
while(n1!=n2){
if(n1>n2)
n1=n1-n2;
else
n2=n2-n1;
}
printf("L.C.M=%d",x*y/n1);
return 0;
}
int main(){
int n1,n2,x,y;
printf("\nEnter two numbers:");
scanf("%d %d",&n1,&n2);
x=n1,y=n2;
while(n1!=n2){
if(n1>n2)
n1=n1-n2;
else
n2=n2-n1;
}
printf("L.C.M=%d",x*y/n1);
return 0;
}
Check the given number is palindrome number or not using c program
#include<stdio.h>
int main(){
int num,r,sum=0,temp;
printf("\nEnter a number:");
scanf("%d",&num);
temp=num;
while(num){
r=num%10;
num=num/10;
sum=sum*10+r;
}
if(temp==sum)
printf("\n%d is a palindrome",temp);
else
printf("\n%d is not a palindrome",temp);
return 0;
}
int main(){
int num,r,sum=0,temp;
printf("\nEnter a number:");
scanf("%d",&num);
temp=num;
while(num){
r=num%10;
num=num/10;
sum=sum*10+r;
}
if(temp==sum)
printf("\n%d is a palindrome",temp);
else
printf("\n%d is not a palindrome",temp);
return 0;
}
Subscribe to:
Posts (Atom)