Students Names: Roll No's: Class: Date: Subject: Assignment Topic
Students Names: Roll No's: Class: Date: Subject: Assignment Topic
Students Names: Roll No's: Class: Date: Subject: Assignment Topic
Question No.1
< For, keyword > < (, operator > < int, keyword > < x, identifier >
< =, operator> < 0, number> <;,separator> < x ,identifier >
< <, operator> < = , operator > < 5 , number > <;,separator>
< x, identifier > < + , operator > < + , operator > < ),
operator >
< ‘\n’,specifier>
< B, identifier > < = , operator > < (, operator > < (, operator >
< c, identifier > < +, operator > < a, identifier > < ),
operator >
< *, operator > < d, identifier > < /, operator > < f, identifier
>
< ‘\n’,specifier>
< while, keyword > < (, operator > < a ,identifier > < < , operator>
< 5, number > < ), operator >
< ‘\n’,specifier> < ‘\t’,specifier> < ‘\t’,specifier> <
‘\t’,specifier>
< a ,identifier > < = , operator >
< a ,identifier > < +, operator > < 1 , number > < char,
keyword >
< MyCourse, identifier > < [, operator > < 5 , number > < ], operator >
< ‘\n’,specifier>
<;, separator> < if, keyword > < (, operator > < a ,identifier >
< <, operator> < b, identifier > <), operator >
< ‘\n’,specifier> < ‘\t’,specifier> < ‘\t’,specifier> <
‘\t’,specifier>
< a, identifier >
< =, operator > < a, identifier > < *, operator > <a
,identifier >
<;,separator> < ‘\n’,specifier>
< else, keyword > < ‘\n’,specifier>
‘\t’,specifier> < ‘\t’,specifier> < ‘\t’,specifier>
< b ,identifier > < = , operator >
< b ,identifier > < *, operator > < b ,identifier >
<;,separator>
Question No.2
A
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
if (*str != 32){
return str;
}
int main(){
char data ;
ifstream infile;
infile.open("file.txt");
cout << "Removed spaces: " << endl;
while(!infile.eof()){
infile>>data;
cout<<removeSpaces(&data);
//cout<<data;
}
cin.ignore();
}
B
#include<iostream>
#include<fstream>
using namespace std;
void remove_multi_comment(char source[], char dest[]){
ifstream fin(source);
ofstream fout(dest);
char ch;
while(!fin.eof())
{
fin.get(ch);
if(ch=='/')
{
fin.get(ch);
if(ch=='*')
while(!fin.eof())
{
fin.get(ch);
if(ch=='/')
break;
}
}
else
fout<<ch;
}
fin.close();
fout.close();
}
int main()
{
char ch;
remove_multi_comment("remove_multi_line_comment.cpp","output.cpp"); /*
function call */
ifstream fin("output.cpp");
while(fin.get(ch))
cout<<ch;
fin.close();
return 0;
}
C,D,E
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main(){
char ch, buffer[15], operators[] = "+-*/%=";
ifstream fin("program.txt");
int i,j=0;
if(!fin.is_open()){
cout<<"error while opening the file\n";
exit(0);
}
while(!fin.eof()){
ch = fin.get();
if(isalnum(ch)){
buffer[j++] = ch;
}
else if((ch == ' ' || ch == '\n') && (j != 0)){
buffer[j] = '\0';
j = 0;
if(isKeyword(buffer) == 1)
cout<<buffer<<" is keyword\n";
else
cout<<buffer<<" is indentifier\n";
}
fin.close();
return 0;
}