You are on page 1of 5

10/8/2021 Software Construction And

Development
Eisha Ter Raazia
2019-BSE-005
Lab2
Code:
Count total number of space,character:
// new.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])


{
char str[100];
int i;
int words=1,characters=0,space=0;
cout<<"Please enter the string \n";
gets(str); //count characters of a string wit out space
i=0;
do{
if(str[i]!=' '){ // check characetrs
characters++;}
else if(str[i]==' ' || str[i] != '\n' || str[i] != '\t'){ // check words
words++;
}
i++;
}
while(str[i] != '\0');
cout<<"\nTotal words: "<<words; //display total number of words
cout<<"\nTotal characters: "<<characters; //display total number of characters
cout<<"\nSpace: "<<(words-1); //display total number of spaces
system("pause");
return 0;
}
Count without space:
// new.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])


{ char str[100];
int i,totChar;
totChar=0;
int space=0;
cout<<"Please enter the string for count characters\n";
gets(str);
i=0;
do{
if(str[i]!=' ') // this condition is used to avoid counting space
{
totChar++;
}
i++;
}while(str[i] != '\0');

cout<<"The total characters of the given string= "<<totChar;


system("pause");
return 0;
}
Task 2:
Create a file (Comiler.cpp) & Implement a Program to read all the content
of a Compiler.cpp (how many lines, how many words and how many
character in the file)

You might also like