8. Stats of text
#include<iostream.h>
#include<conio.h>
#include<process.h>
void textstat( char str[], int &lc, int &wc, int &cc);
void main()
{ clrscr();
char str[255] = “ Hi how are you !! ”;
int lc, wc, cc;
cout<<“n Enter any string (~ to terminate) : “;
cin.getline(str, 255,’~’)
textstat(str, lc, wc, cc);
cout<< “number of lines in the string are: “<< lc;
cout<< “number of words in the string are: “<< wc;
cout<< “number of characters in the string are: “<< cc;
getch();
}
int wordcount(char str[])
{ int count = 1;
for (int i = 0; str[i] ‘0’; ++i)
{ if (str[i] == ‘i’ || str[i] == ‘n’)
{count ++;
while (str[i] ==‘ ‘)
i++; }
if (str[i]==‘0’)
i--;
}
return count;
}
int charcount(char str[])
int count = 0;
for (int i = 0; str[i] ‘0’; ++i)
count++;
return count;
}
int linecount(char str[])
{ int count = 1;
for (int i = 0; str[i] ‘0’; ++i)
if(str[i]==‘n’)
count++;
return count;
}
void textstat( char str[], int &lc, int &wc, int &cc)
{ lc = linecount(str);
wc = wordcount(str);
cc = charcount(str);
}
9. Nested structures#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct addr
{ int houseno;
char area[25];
char city[25];
char state[25];
};
struct emp
{
int empno;
char name[25];
char desig[25];
addr address;
float basic;
} worker;
int main ()
{ clrscr();
cout<<" n Enter employee number:"
cin>>worker.empno;
cout<<" n Enter name:"
gets(worker.name);
cout<<" n Enter Designation:"
gets(worker.desig);
cout<<" n Enter House no. :"
gets(worker.address.houseno);
cout<<" n Enter Area"
gets(worker.address.area);
cout<<" n Enter city
getsworker.address.city);
cout<<" n Enter state"
gets(worker.address.state);
cout<<" n Enter Basic pay "
cin>>worker.basic;
return0;
}
10. Student’s Result#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct student
{
int rollno;
char name[25];
float marks;
char grade;
};
student learner;
void main ()
{
clrscr();
cout<<" n Enter roll number:"
cin>>learner.rollno;
cout<<" n Enter name:"
gets(learner.name);
cout<<" n marks in 5 subjects:"
for (int i = 0;i < 5 ; ++i)
{
cout<<"Subject"<< i + 1 <<": ";
cin>>learner.marks[i];
}
float avg, total = 0;
for (int i = 0;i < 5 ; ++i)
total += sum[i];
avg = total/ 5;
if (avg < 50) learner.grade = 'F';
else if (avg < 60) learner.grade = 'C';
else if (avg < 80) learner.grade = 'B';
else lerner.grade = 'A'
cout<<" n Student's Result :"
cout<<" n roll number :"<<learner.rollno;
cout<<" n Name :'
puts(learner.name);
cout<<" n Total marks :"<< total;
cout<<" n Grade :"<<learner.grade <<endl;
}
cout<<" n Enter Basic pay "
cin>>worker.basic;
return 0;
}