Read in your tongue here..
Monday, October 21, 2013
Basics in Classes using C++.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class stu{
public:
int roll,m[3];
char name[45];
void input()
{
cout<<"Enter roll number:";
cin>>roll;
cout<<"Enter name:";
gets(name);
cout<<"Enter marks of three subjects:";
cin>>m[0]>>m[1]>>m[2];
}
int total()
{
return(m[0]+m[1]+m[2]);
}
void display()
{
cout<<"Name:"<<name<<"\tRoll number: "<<roll;
cout<<"\nMarks of three subjects: "<<m[0]<<'\t'<<m[1]<<'\t'<<m[2];
cout<<"\n\tTotal marks= "<<total();
cout<<endl;
}
};
void main()
{
stu s1,s2;
s1.input();
s2.input();
s1.display();
s2.display();
getch();
clrscr();
}
#include<stdio.h>
#include<conio.h>
class stu{
public:
int roll,m[3];
char name[45];
void input()
{
cout<<"Enter roll number:";
cin>>roll;
cout<<"Enter name:";
gets(name);
cout<<"Enter marks of three subjects:";
cin>>m[0]>>m[1]>>m[2];
}
int total()
{
return(m[0]+m[1]+m[2]);
}
void display()
{
cout<<"Name:"<<name<<"\tRoll number: "<<roll;
cout<<"\nMarks of three subjects: "<<m[0]<<'\t'<<m[1]<<'\t'<<m[2];
cout<<"\n\tTotal marks= "<<total();
cout<<endl;
}
};
void main()
{
stu s1,s2;
s1.input();
s2.input();
s1.display();
s2.display();
getch();
clrscr();
}
Sunday, October 20, 2013
Calculating total number of words and lines in a string using C++.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
char stm[100];
cout<<"Enter string:";
gets(stm);
int i,s=0,l=0;
for(i=0;stm[i]!=NULL;i++)
{
if(stm[i]==' ')
s++;
if(stm[i]=='.')
l++;
}
cout<<"Total number of:\nWords="<<s+1<<"\nLines="<<l;
getch();
clrscr();
}
#include<conio.h>
#include<stdio.h>
void main()
{
char stm[100];
cout<<"Enter string:";
gets(stm);
int i,s=0,l=0;
for(i=0;stm[i]!=NULL;i++)
{
if(stm[i]==' ')
s++;
if(stm[i]=='.')
l++;
}
cout<<"Total number of:\nWords="<<s+1<<"\nLines="<<l;
getch();
clrscr();
}
Finding number of characters, spaces, lower and upper case characters in C++.
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
char stm[345];
int l,i,s=0,up=0,lw=0,c;
cout<<"Enter string:";
gets(stm);
l=strlen(stm);
for(i=0;i<l;i++)
{
if(stm[i]==' ')
s++;
if(isupper(stm[i]))
up++;
if(islower(stm[i]))
lw++;
}
cout<<"Total number of: \nCharacters=";
cout<<l<<"\nSpaces="<<s<<"\nLower case characters="<<lw<<"\nUpper case characters="<<up;
getch();
clrscr();
}
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
char stm[345];
int l,i,s=0,up=0,lw=0,c;
cout<<"Enter string:";
gets(stm);
l=strlen(stm);
for(i=0;i<l;i++)
{
if(stm[i]==' ')
s++;
if(isupper(stm[i]))
up++;
if(islower(stm[i]))
lw++;
}
cout<<"Total number of: \nCharacters=";
cout<<l<<"\nSpaces="<<s<<"\nLower case characters="<<lw<<"\nUpper case characters="<<up;
getch();
clrscr();
}
Sunday, October 6, 2013
Stroing student's details using array in c++.
#define size 10
#include<iostream.h>
#include<conio.h>
void main()
{
void line(void);
char g[size],name[size][45],course[size][5],sem[size][10],ses[size][10],sub[size][5][20];
int roll[size],i=0,j=0;
float m[size][5],t[size],p[size],sum=0;
cout<<"Enter details:\n";
while(i!=size)
{
cout<<"Student "<<i+1<<":\nName:";
cin>>name[i];
cout<<"Roll:";
cin>>roll[i];
cout<<"Enter course:";
cin>>course[i];
cout<<"Enter semester:";
cin>>sem[i];
cout<<"Enter session:";
cin>>ses[i];
while(j!=5)
{
cout<<"Enter subject "<<j+1<<':';
cin>>sub[i][j];
cout<<"Enter marks obtained in "<<sub[i][j]<<':';
cin>>m[i][j];
sum=sum+m[i][j];
j++;
}
t[i]=sum;
p[i]=t[i]/5;
if(p[i]>=75)
g[i]='A';
else if(p[i]>=60)
g[i]='B';
else if(p[i]>=50)
g[i]='C';
else
g[i]='F';
i++;
j=0;
sum=0;
clrscr();
}
i=0;
cout<<"\n\tMarks Details\n***********************************\n";
while(i!=size)
{
cout<<"|Course: "<<course[i]<<"\tSemester: "<<sem[i];
cout<<" |\n|Roll: "<<roll[i]<<"\tSession: "<<ses[i];
cout<<"|\n|Name: "<<name[i]<<endl<<"|Subjects:\n";
line();
cout<<endl;
for(j=0;j<5;j++)
cout<<'|'<<sub[i][j]<<"|\t";
cout<<endl;
line();
cout<<endl;
for(j=0;j<5;j++)
cout<<'|'<<m[i][j]<<"|\t";
cout<<endl;
line();
cout<<"\n|Total: "<<t[i]<<"\t|Percentage: "<<p[i];
cout<<"\n\t Grade: "<<g[i]<<endl;
i++;
line();
}
getch();
clrscr();
}
void line (void)
{
int i=0;
while(i!=38)
{
cout<<'-';
i++;
}
}
#include<iostream.h>
#include<conio.h>
void main()
{
void line(void);
char g[size],name[size][45],course[size][5],sem[size][10],ses[size][10],sub[size][5][20];
int roll[size],i=0,j=0;
float m[size][5],t[size],p[size],sum=0;
cout<<"Enter details:\n";
while(i!=size)
{
cout<<"Student "<<i+1<<":\nName:";
cin>>name[i];
cout<<"Roll:";
cin>>roll[i];
cout<<"Enter course:";
cin>>course[i];
cout<<"Enter semester:";
cin>>sem[i];
cout<<"Enter session:";
cin>>ses[i];
while(j!=5)
{
cout<<"Enter subject "<<j+1<<':';
cin>>sub[i][j];
cout<<"Enter marks obtained in "<<sub[i][j]<<':';
cin>>m[i][j];
sum=sum+m[i][j];
j++;
}
t[i]=sum;
p[i]=t[i]/5;
if(p[i]>=75)
g[i]='A';
else if(p[i]>=60)
g[i]='B';
else if(p[i]>=50)
g[i]='C';
else
g[i]='F';
i++;
j=0;
sum=0;
clrscr();
}
i=0;
cout<<"\n\tMarks Details\n***********************************\n";
while(i!=size)
{
cout<<"|Course: "<<course[i]<<"\tSemester: "<<sem[i];
cout<<" |\n|Roll: "<<roll[i]<<"\tSession: "<<ses[i];
cout<<"|\n|Name: "<<name[i]<<endl<<"|Subjects:\n";
line();
cout<<endl;
for(j=0;j<5;j++)
cout<<'|'<<sub[i][j]<<"|\t";
cout<<endl;
line();
cout<<endl;
for(j=0;j<5;j++)
cout<<'|'<<m[i][j]<<"|\t";
cout<<endl;
line();
cout<<"\n|Total: "<<t[i]<<"\t|Percentage: "<<p[i];
cout<<"\n\t Grade: "<<g[i]<<endl;
i++;
line();
}
getch();
clrscr();
}
void line (void)
{
int i=0;
while(i!=38)
{
cout<<'-';
i++;
}
}
Subscribe to:
Posts (Atom)