C++ Program Write Object on File

This is a Cpp (C++) program for file handling which stores a object on a file. This file stores the student details from the student class object directly by writing the object onto the file. This is also called serialization.
This is a part of Mumbai University MCA Colleges C++ MCA Sem 3

#include<stdio.h>
#include<conio.h>
#include<math.h>
class Student
{
int roll_no;
char cname[20];
public:
void setrollno()
{
cout<<"Enter the rollno:"<<endl;
cin>>roll_no;
}
void setname()
{
cout<<"\nEnter name:"<<endl;
cin>>cname;
}
int getno()
{
return roll_no;
}
char * getname()
{
return cname;
}
};
void main()
{
clrscr();
ofstream sfil("STUDENT");
Student st;
st.setrollno();
st.setname();
sfil<<st.getno();<<' ';
sfil<<st.getname();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C++ Program File Handling Read/Write

This is a simple File Handling Program in C++ for writing and reading a file using streams. This is a part of Mumbai University MCA Colleges Cpp MCA Sem 3



#include<iostream.h>
#include<fstream.h>
#include<math.h>
void main()
{
clrscr();
ofstream fout("Myfile");
fout<<"Ganesh";
fout.close();
ifstream fin("Myfile");
char ch;
while(fin)
{
fin.get(ch);
cout<<ch;
}
fin.close();
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Converting Number to Words Javascript Indian Format

The Below code is used for number to words conversion ( Indian Format). The logic used can be implement in any other language. I have used java script here but if you understand the logic then you can recreate it using any other language.



Enter the Number here.




The Code for the above logic is as follows.


<script language="javascript">


function numToString(x)
{
var r=0;
var txter=x;
var sizer=txter.length;
var numStr="";
if(isNaN(txter))
{
alert(" Invalid number");
exit();
}
var n=parseInt(x);
var places=0;
var str="";
var entry=0;
while(n>=1)
{
r=parseInt(n%10);

if(places<3 && entry==0)
{
numStr=txter.substring(txter.length-0,txter.length-3) // Checks for 1 to 999.
str=onlyDigit(numStr); //Calls function for last 3 digits of the value.
entry=1;
}

if(places==3)
{
numStr=txter.substring(txter.length-5,txter.length-3)
if(numStr!="")
{
str=onlyDigit(numStr)+ " Thousand "+str;
}
}

if(places==5)
{
numStr=txter.substring(txter.length-7,txter.length-5) //Substring for 5 place to 7 place of the string
if(numStr!="")
{
str=onlyDigit(numStr)+ " Lakhs "+str; //Appends the word lakhs to it
}
}

if(places==6)
{
numStr=txter.substring(txter.length-9,txter.length-7)  //Substring for 7 place to 8 place of the string
if(numStr!="")
{
str=onlyDigit(numStr)+ " Crores "+str;        //Appends the word Crores
}
}

n=parseInt(n/10);
places++;
}
alert(str);
}




function onlyDigit(n)
{
//Arrays to store the string equivalent of the number to convert in words
var units=['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine'];
var randomer=['','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen'];
var tens=['','Ten','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'];
var r=0;
var num=parseInt(n);
var str="";
var pl="";
var tenser="";
while(num>=1)
{
r=parseInt(num%10);
tenser=r+tenser;
if(tenser<=19 && tenser>10) //Logic for 10 to 19 numbers
{
str=randomer[tenser-10];
}
else
{
if(pl==0)        //If units place then call units array.
{
str=units[r];
}
else if(pl==1)    //If tens place then call tens array.
{
str=tens[r]+" "+str;
}
}
if(pl==2)        //If hundreds place then call units array.
{
str=units[r]+" Hundred "+str;
}

num=parseInt(num/10);
pl++;
}
return str;
}

</script>




<form name="fm" id="fm">

<input type="text"  name="txtinput" id="txtinput" maxlength="9" />
<input type="button" onclick="numToString(txtinput.value)" id="show" />

</form>

C Program Leap Year MCA Sem 1

This C program finds if the input year is a Leap Year or not. This is a part of Mumbai University MCA Colleges C programs MCA Sem 1.
Leap year is any year which is divisible by 4.

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
clrscr();
int year;
printf("Enter the year to find if it is leap year or not:");
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)
{
printf("The year entered is a leap year.");
}
else
{
printf("The year entered is not a leap year.");
}
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C Program Keypress identification MCA Sem 1

This C program take in a Key Press and displays if its a number , character (small or Big) or Special character. This program is part of Mumbai University MCA Colleges C programs MCA Sem 1. 
This program uses the concepts of ASCII values on the keyboard press.

#include<stdio.h>
void main()
{
char c,ans;
do{
fflush(stdin);
printf("Enter character");
scanf("%c",&c);
if(c>=65 && c<=90)
{
printf("Entered character is capital letter");
}
if(c>=97 && c<=122)
{
printf("SMALL LETTERS");
}
if(c>=48 && c<=57)
{
printf("DIGIT");
}
if(c>=32 && c<=47)
{
printf("SPECIAL CHARACTER");
}
fflush(stdin);
printf("do u want to continue y/n");
scanf("%c",&ans);
}
while(ans!='n');
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C program Number to Text 2 conversion

This C program will convert the number to words in tens and units place respectively. This is a part of Mumbai University MCA Colleges C programs MCA Sem 1
Out put as

Input:- 12345
Output:- twelve thousand three hundred fourty five


#include<stdio.h>

void pw(long,char[]);//function
char *unit[]={" "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety"};

void main()
{
long n;
printf("Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");//Will give either 1 or 2 digit answer
pw(((n/100000)%100),"lakh");//Will give either 1 or 2 digit answer
pw(((n/1000)%100),"thousand");//Will give either 1 or 2 digit answer
pw(((n/100)%10),"hundred");//Will always give 1 digit answer
pw((n%100)," ");////Will give always 2 digit answer
}
}


void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],unit[n%10]):printf("%s ",unit[n]);
/*This if condition will execute if n is greater than 0 and used to print crore, lakh, thousand and hundred
This is used so that if say we enter 12000 the answer must be "twelve thousand"
If you omit the if statement and simply write the print statement the output would be like
"twelve thousand hundred" which is not the right one
*/
if(n)
printf("%s ",ch);
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C Program Triangle Area 2 Methods

This C program finds the area of Triangle using 2 methods. This is a part of Mumbai University MCA College C Programs MCA Sem 1.

The area of triangle can be found by knowing its height and width or by knowing the length of all side.

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{ clrscr();
float bs,ht,a,b,c,s;
float area;
int k;
printf("If you want to use base n height method then enter 1\n");
printf("If you want to use sides method then enter 2\n");
printf("Enter your choice:");
scanf("%d",&k);
switch(k)
{
case 1:
printf("Enter the base and the height of the triangle:");
scanf("%f%f",&bs,&ht);
area=0.5*bs*ht;
break;

case 2:
printf("Enter the three sides of the triangle:");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
break;
}
printf("The area of the triangle is:%f",area);
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C Program Number to Text Conversion

This is a C program for converting a number to its textual equivalent. Output as.
23 - two three.
This is a part of Mumbai University MCA College C program MCA Sem 1

#include<stdio.h>

void pw(long); //function
char *unit[]={" zero"," one"," two"," three"," four"," five"," six"," seven"," eight"," nine"};

void main()
{
long n,x=100000000;
printf("Enter upto 9 digit number\n");
scanf("%ld",&n);
if(n<=0)
printf("Enter a positive number\n");
else
{
//This will truncate zeros at start if any and if not present then set value of x appropriately
while(((n/x)%10)==0)
x=x/10;
//Actual logic to print words starts here
while(x>0)
{
pw((n/x)%10);
x/=10;
}
}
}
void pw(long n)
{
printf("%s",unit[n]);
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.