You are on page 1of 12



24. WAP to input the name of text file from user and display.
a. No. of blank spaces present in file
b. No. of line present in file
c. No. of Capital alphabets present file
d. No. of small alphabets present in file
e. No. of line have Capital alphabets starting in file
f. No. of words present in file
g. No. of digits present
h. No. of words ending with vowel.
Ans. #include<fstream.h>
void main()
ifstream ifile;
char fname[20];
cout<<"\n\nenter file name ";
cout<<"\ncould not open file "<<fname;
char ch,cb='0';
int blank=0,line=0,cap=0,small=0,capstart=0,words=0;
int digits=0,wordsendvowel=0,flag=0;
if(isupper(ch) && flag==0)
if(cb=='\n' && isupper(ch))
if(isspace(cb)&& !isspace(ch))
if(isspace(ch) && isupper(cb=='a'||cb=='e'||cb=='i'||cb=='o'||cb=='u') || (cb=='\n'))

cout<<"\nNo. ifile. of blank space in file "<< } else { while(!ifile. Ans. } ifile. cin>>str.h> void main() { ifstream ifile. } 25.h> #include<string. of Small alphabets "<<small. cout<<"\nNo.h> #include<conio.word[20].close(). } cout<<endl. Then input a string and search for it in the file and display the status whether it is present in the file or not. int count=0. cout<<"\nNo. cin>>fname. of line starting with Capital alphabets "<<capstart.h> #include<conio. of Capital alphabets "<<cap. char fname[20].of words ending with vowel "<<wordsendvowel. of line present in file"<<line. cout<<"\nenter String ". str[20]. cout<<"\nNo. cout<<"\n\nEnter file Name : ". #include<fstream. if(!ifile) { cerr<<"\n File can't be opened ! \n". WAP to input the name of a text file from the user. cout<<"\nNo. of digits present in a file "<<digits. cout<<"\nNo. cout<<"\nNo. cout<<"\nNo. getch(). of words present in file "<<words.eof()) { . cout<<ch.

h> #include<conio.cb. #include<fstream.h> #include<string. } ifile. if(!ifile) { cerr<<"\n File can't be opened ! \n". cout<<"\nenter charcater ".h> void main() { ifstream ifile. cin>>fname. ch. Ans. while(!ifile. cout<<"\n\nEnter file Name : ". cout<< } getch(). cin>>chinput. int count=0. char fname[20].open(fname). ofstream ofile("temp"). } cout<<"\n Count of "<<str<<" is "<<count++.get(ch). if(strcmp(word.ifile>>word.h> #include<stdio. ifile. ifile.h> #include<ctype.close().eof()) { for this input the name of a text file from the user then input the characters and search for the first character of word in the file and replace it with the second character.h> #include<stdlib. } . } 26. WAP to perform SEARCH and REPLACE operations on a text file .chinput.str)==0) count++.word[20].

} ifile.get(cf).dat and COMP2. #include<fstream. while(!ifile.close().get(ch).eof()) { ifile.put(cf). cb=ch. else { while(!ifile. ofile. if(chinput==ch && isspace(cb)) { ifile.get(ch).close().h> . cout<<"\n File after replacing character with next character is \n\n\n".eof()) { ifile.dat Ans.put(ch). } 27. cout<<ch. } ifile.dat each of the files should have records with the following fields: Empno integer Name A string of 20 characters Salary A floating point number Both the files should have created in increasing order of employee no your program should then merge the files & then obtain a third file NEWCMP. ofile. Create two payroll files COMP1. fname).put(ch).close(). } else ofile. remove(fname). getch(). rename ("temp".open(fname). } ifile. ofile.

} size=sizeof(employee). float salary.empno<<"\t"<< cout<<"\nEnter Employee name : ". f2."" cin>>e.salary.size).close(). .dat"). f3.h> struct employee { int empno.emp2. char name[21].dat"). if((!f1)||(!f2)||(!f3)) { cout<<"cannot open the files". outfile. ofstream<<"\t"<<e. cout<<"Enter Employee no : ". while(infile) { infile. cout<<"\n\t"<<e.size).read((char*)&e.f2.salary. cout<<"\nRecords of file "<<file.dat").ios::in). while(f1 && f2) { if(flag==0) { f1.close().dat").name). cout<<"\nEnter Salary : ". employee e. cin>>e. int size.sizeof(e)). f1. void append(char *file) { ofstream outfile.empno. outfile. outfile. return 1. ifstream f1. }.read((char*)&emp1. cout<<"\n\t\tEmpno\tName\tSalary". } void display(char *file) { ifstream infile. }*)&emp2. } int merge() { employee emp1.#include<stdio.write((char*)&e. infile.ios::app).open("comp1.h> #include<conio. gets(e. int flag=0. remove("newcmp.

dat".size).size).size).Merge comp1. case 3: merge(). cout<<"\n\nEnter your choice : ".close().write((char*) &emp2.size). f2. } f1. } while(f2) { f3. f1.empno) { f3.close(). break.size).dat").dat").*)&emp2.dat").dat". while(ch!=4) { clrscr(). case 2: append("comp2. cout<<"\n3. cout<<"\n2. display("newcmp. display("comp1. break.Exit".dat").read((char*)&emp2. cout<<"\n4. flag=1.write((char*)&emp2.write((char*)&emp1.close().dat to newcmp.dat and comp2.size).Enter record in comp2.empno<emp2. } } while(f1) { f3. cin>>ch.size).read((char*)&*)&emp2. cout<<"\n1.write((char*)&emp1. display("comp2. } } } . switch(ch) { case 1: append("comp1. break. } if(emp1. } void main() { int ch=0.dat". f2.size). f2.dat"). return 0. } else { f3.Enter record in comp1. f3.

char A[]). cout<<"\n2. clrscr(). void generate(struct node **. void search(struct node *.Search by Roll no: ". cout<<"Enter the number of nodes: ". int key. cout<<"\n1. int). generate(& }. int main() { struct node *head = NULL. search(head. num). void search(struct node *. char name[15]. Then perform search operations for name as well as roll no.28. Ans. } if(key==2) { cout<<"\nEnter roll no : ". cin>>name.roll.h> #include<conio. on this list. char name[20].Search by name : ".h> struct node { int rn.h> #include <string. int). if(key==1) {cout<<"\nenter name : ". cin>>num. #include<iostream. num. struct node *next.h> #include <stdlib. WAP to create a linked list in which each node contains the roll number and name of the student. . cin>>key. cout<<"\nDisplaying the list\n".

} void search(struct node *head. } void generate(struct node **head. } getch(). roll). cout<<"Enter roll no :". int key) { while (head != NULL) { if (head->rn == key) { cout<<"key found\n". for (i = 0. i < num. getch(). cin>>roll. cin>>temp->name. search(head. char name[20]. cout<<head->name<<" "<<head->rn. int num) { int i. . } } } void search(struct node *head. cout<<head->name<<" "<<head->rn. } head = head->next. *head = temp. return. temp->next = NULL. key)==0) { cout<<"key found\n". char key[]) { while (head != NULL) { if (strcmp(head->name. } else { temp->next = *head. cin>>temp->rn. return 0. struct node *temp.roll. if (*head == NULL) { *head = temp. i++) { temp = (struct node *)malloc(sizeof(struct node)). return. cout<<"Enter name : ". } cout<<"Key not found\n".

} head = head->next.choice. DISPLAY(). } cout<<"Key not found\n". WAP to perform basic operation on STACK : PUSH(). void display(node * top). int main() { node *top.h> #include<conio. node *next. int val.h> struct node{ int data. val). getch(). } 29. }. Ans. #include<iostream. node *push(node *top. int & val). node *pop(node *top.POP(). .

cout<<"\n The Stack is .val). if(top==NULL) { cout<<"\n Stack empty". cout<<"\n\n Enter your choice ". if(val!=-9999) cout<<"\n Poped value is . . int & val) { node *x. val=x->data. cout<<"\n4. do { cout<<"\n\n MENU". delete x. cout<<"\n2. cin>>val. POP". break. } void display(node * top) { node *ptr. ptr=top.val). top=top->next. top=push(top.". val=-9999. while(ptr!=NULL) { cout<<ptr->data<<" ". PUSH". } }while(choice!=4). cout<<"\n3. cout<<"\n\ val) { node *x. x=new node. } return(top). return (top). break. x->data=val. return 0..clrscr(). } else { x=top."<<val. Display". x->next=top.. switch(choice) { case 1:cout<<"\n Enter the value to be pushed"... top=x. } node *pop(node *top. case 3:display(top). break. } node *push(node *top. Quit". case 2:top=pop(top.. cin>>choice.

temp.*tmp.h> #include<conio. charnode *start. }. Ans. WAP to create a LINKED List as STACK & display String in Reverse order. . } } 30.h> #include<stdio.h> struct charnode{ char ch. charnode *next. ptr=ptr->next. #include<iostream.*ptr.

delete temp. start=NULL. charnode *temp. start=ptr.char ok. cout<<"Name in reverse order is as \n". ptr->next=start. while(tmp!=NULL) popchar(). } . } void main(void) { clrscr(). tmp=start. while((ok=getchar())!='\n') pushchar(). void pushchar(void) { ptr=new charnode. } void popchar(void) { cout<<tmp->ch. ptr->ch=ok. tmp=tmp->next. getch(). cout<<"Enter name ". cout<<endl. temp=tmp.