السلام عليكم
الاخوة الاعزاء
عندي واجب على الرابط التالي:
http://orion.cudenver.edu/1410sp08/homewor...6_1410_sp08.pdf
محاولتي هي:
الملف الاول هو:
pa6.cpp
#include <iostream>
#include <iomanip>
#include "pa6functions.h"
using namespace std;
int main()
{
string str;
pa6 mypa6;
cout << "************************************"<<endl;
cout << " Program Assignment 6 "<<endl;
cout << "************************************"<<endl;
cout << "Please Write a sentence -> ";
getline(cin,str);
cout << "Count Word = " << mypa6.CountWord(str)<<endl;
cout << "Count Smallest = " << mypa6.CountSmallest(str)<<endl;
cout << "Count Largest = " <<
mypa6.CountWord(str)-mypa6.CountSmallest(str) <<endl;
// cout<<mypa6.CountLetter (str,'a')<<endl;
cout << "-------------------" <<endl;
cout << "| Letter |" << " | Count |"<<endl;
cout << "-------------------" <<endl;
for(int i=int('a'); i<=int('z');i++)
cout << "| "<<char(i)<<" |"<<"| "<<setw(5)<<setfill('0')<<mypa6.CountLetter(str,char(i))<<" |"<<endl;
for(int i=int('A');i<=int('Z');i++)
cout <<"| "<<char(i)<<" |"<<"| "<<setw(5)<<setfill('0')<<mypa6.CountLetter(str,char(i))<<" |"<<endl;
cout <<"| "<<"."<<" |"<<"| "<<setw(5)<<setfill('0')<<mypa6.CountLetter(str,'.')<<" |"<<endl;
return 0;
}ملف pa6functions.h
#include <string>
using std::string;
class pa6
{
public:
int CountWord(string);
int CountLetter(string,char);
int CountSmallest(string);
};ملف pa6functions.cpp
#include <cctype>
#include "pa6functions.h"
int pa6::CountWord(string str)
{ int t=0;
for(int i=0; i<str.length();i++)
{if(str==' ' && str[i+1]!=' ') t++;}
if(str[0]==' ') t--;
return (++t);
}
int pa6::CountSmallest(string str)
{int t=0;
for(int i=0; i<str.length(); i++)
{if( isspace(str) && (islower(str[i+1]) )) t++;}
if(islower(str[0])) t++;
return t;
}
int pa6::CountLetter(string str, char a)
{
int t=0;
for(int i=0; i<str.length(); i++)
if(str==a) t++;
return t;
}و output هو كالتالي
[username@ouray ~]$ ./a.out ************************************ Program Assignment 6 ************************************ Please Write a sentence -> Today is a wonderful day! Count Word = 5 Count Smallest = 4 Count Largest = 1 ------------------- | Letter | | Count | ------------------- | a || 00003 | | b || 00000 | | c || 00000 | | d || 00003 | | e || 00001 | | f || 00001 | | g || 00000 | | h || 00000 | | i || 00001 | | j || 00000 | | k || 00000 | | l || 00001 | | m || 00000 | | n || 00001 | | o || 00002 | | p || 00000 | | q || 00000 | | r || 00001 | | s || 00001 | | t || 00000 | | u || 00001 | | v || 00000 | | w || 00001 | | x || 00000 | | y || 00002 | | z || 00000 | | A || 00000 | | B || 00000 | | C || 00000 | | D || 00000 | | E || 00000 | | F || 00000 | | G || 00000 | | H || 00000 | | I || 00000 | | J || 00000 | | K || 00000 | | L || 00000 | | M || 00000 | | N || 00000 | | O || 00000 | | P || 00000 | | Q || 00000 | | R || 00000 | | S || 00000 | | T || 00001 | | U || 00000 | | V || 00000 | | W || 00000 | | X || 00000 | | Y || 00000 | | Z || 00000 | | . || 00000 |
وإن شاء الله ماراح تقصرون معي
خالص المودة,