Пример #1
0
std::ostream &print(std::ostream &os, const QueryResult &q) {
    os << q.word << " occurs " << q.lines->size() << " "
       << make_plural(q.lines->size(), "time") << std::endl;
    for (auto num : *q.lines) {
        os << "\t(line " << num + 1 << ") "
           << *(q.text->begin() + num) << std::endl;
    }
    return os;
}
Пример #2
0
std::ostream& print(std::ostream& os, const QueryResult& qr)
{
	// if the word was found, print the count and all occurrences
	os << qr.sought << " occurs " << qr.lines->size() << " "
	   << make_plural(qr.lines->size(), "time", "s") << std::endl;
	// print each line in which the word appeared
	for(auto num : *qr.lines)
		os << "\t(line " << num + 1 << ") "
	       <<*(qr.file->begin() + num) << std::endl;
	return os;
}
Пример #3
0
std::ostream &print(std::ostream& os, const QueryResult &qr)
{
	os << qr.key << " occurs " << qr.lines->size() 
		<< make_plural(" time", qr.lines->size()) << "\n";

	// print lines that the key word appears
	for (const auto &num : *qr.lines)      
	{
		os << "(line " << num + 1 << ") " 
		    << *(qr.file->begin() + num) << std::endl;
	}
	return os;
}
Пример #4
0
void biggies(std::vector<std::string> &words, std::vector<std::string>::size_type st) {
    elimDups(words);
    stable_sort(words.begin(), words.end(),
                [](const std::string &a, const std::string &b)
                  { return a.size() < b.size(); });
    auto wc = find_if(words.begin(), words.end(),
                      [st](const std::string &a) { return a.size() >= st; });

    auto count = words.end() - wc;
    std::cout << count << " " << make_plural(count, "word", "s")
              << " of length " << st << " or longer" << std::endl;
    
    for_each(wc, words.end(), [](const std::string &s) { std::cout << s << " "; });
    std::cout << std::endl;
}                      
Пример #5
0
        // when not use QueryResult and do the same as print().
        void query_and_print(const std::string &word) const
        {
            auto pos = word_map_.find(word);

            if (pos != word_map_.end())
            {
                // *cxx-map-find*
                std::cout << word << " occurs " << pos->second->size() << " "
                    << make_plural(pos->second->size(), "time", "s") << std::endl;

                for (auto e : *pos->second)
                    std::cout << "(line " << e+1 << ") " << (*input_file_)[e] << std::endl;
            }
            else
                std::cout << word << " not found" << std::endl;
        }
Пример #6
0
void TestCountIfByBind()
{
    std::string str = "the quick red fox jumps over the slow red turtle";
    std::istringstream iss(str);
    std::string word;
    std::vector<std::string> words;

    while (iss >> word)
    {
        words.push_back(word);
    }

    int sz = 4;
    int count = count_if(words.begin(), words.end(), bind(CheckSize, std::placeholders::_1, sz));

    std::cout << "there are " << count << " " << make_plural(count, "word", "s") << " that the length no longer that " << sz << std::endl;
}
int
main(void)
{

    FILE *fp, *fp2, *fp3; /*File pointers*/
    char hard[7], soft[7], flat[7], round[7]; /*Input vowels*/ 
    char plural[15][20]; /*Output plural nouns*/
    char word[15][20]; /*Input nouns*/
    bool control; /*Whether it is harmonies*/
    int i; /*For loops*/
    int size=0; /*Number of nouns*/
    
    /*Open Vowels.txt if couldn't open print the screen warning message*/
    fp=fopen(VOWELS, "r");
    if(fp==NULL)
        printf("Vowels.txt counldn't open...");
    
    /*Reads vowels from file*/
    fgets(hard,7,fp);
    fgets(soft,7,fp);
    fgets(flat,7,fp);
    fgets(round,7,fp);
    
    fclose(fp);
    
    /*Open Nouns.txt if couldn't open print the screen warning message*/
    fp2=fopen(NOUNS, "r");
    if(fp2==NULL)
        printf("Nouns.txt counldn't open...");
    
    /*Reads nouns from file*/
    i=0;
    while(fscanf(fp, " %s", word[i])!=EOF)
    {
        size++;
        i++;   
    }
    
    fclose(fp2);
    
/*##########################Print the screen results##########################*/
    printf("\n%10cMajor%4cMinor", ' ', ' ');
    
    for(i=0;i<size;i++)
    {
        printf("\n%-12s", word[i]);
                       
        
        control=is_major_vh_word(word[i], hard, soft);
        if(control==1)
            printf("T%8c", ' ');
        else
            printf("F%8c", ' ');
        
        control=is_minor_vh_word(word[i], flat, round);
        if(control==1)
            printf("T");
        else
            printf("F");        
      
    }
    
    printf("\n\n<<<<Plural of the nouns>>>>");
    for(i=0;i<size;i++)
    {
        make_plural(word[i] , plural[i], hard, soft);
        printf("\n%s---%s", word[i],plural[i]);
    }
         
    printf("\n\n");
    
    /*Open Plural.txt if couldn't open print the screen warning message*/
    fp3=fopen(PLURAL, "w");
    if(fp3==NULL)
        printf("Plural.txt counldn't open...");
    
    /*Writes to file plural nouns*/
    for(i=0;i<size;i++)
    {
        make_plural(word[i] , plural[i], hard, soft);
        fprintf(fp3,"%s\n",plural[i]);
    }    
        
    
    
    return 0;
}
int main() {
	char word[NUM_NAMES][LETTER],v_hard[3],v_soft[2],v_flat[3],v_round[2];/*
	defines the strings arrays*/
	char plural_noun[NUM_NAMES],pl_noun[NUM_NAMES+3];/*defines the nouns 
	arrays*/
	char cell,a;/*defines the char*/
	int i,k=0,row=0;/*defines the integers for loop*/
	bool c, d;/*defines the bool values*/
	FILE *inp;/*defines the vowels file*/
	inp=fopen("Vowels.txt","r");/*open file*/
	/*this loop for scan the vowels until EOF*/
	while( fscanf(inp,"%c",&cell)!=EOF )
	{	/*this control change the array*/
   		if(cell=='\n') {
			row=0;
			a=cell;
              		k++;
                 }
		/*scan the hard letter array*/
                 else if(k==0)
		 {
			v_hard[row]=cell;			
			row++;
			
                  }
		/*scan the soft letter array*/
		 else if(k==1)
		 {
			v_soft[row]=cell;
			row++;
                  }
		/*scan the flat letter array*/
		 else if(k==2)
		 {
			v_flat[row]=cell;
			row++;
                  }
		/*scan the round letter array*/
		 else if(k==3)
		 {
			v_round[row]=cell;
			row++;
                  }
	}
	fclose(inp);/*close file*/
	FILE *inp2;/*define the nouns file*/
	inp2=fopen("Nouns.txt","r");/*open the file*/
	i=0;
	/*this loop scan the words array from the file*/ 
	while(fscanf(inp,"%s",word[i])!=EOF) {
	i++;
	}
	fclose(inp2);/*close the file*/ 
	printf("Reading the vowels..\n");
	printf("Reading the nouns..\n");
	printf("The maintaince harmonies\n");
	printf("		MAJOR		MINOR\n");
	/*this loop doing control  word for major and minor harmony rules*/
	for(i=0;i<9;i++) {
		printf("%s		",word[i]);
		c=is_major_vh_word(word[i],v_hard,v_soft);
		if(c==TRUE) printf("T		");
		else printf("F		");
		d=is_minor_vh_word(word[i],v_flat,v_round);
		if(d==TRUE) printf("T\n");
		else printf("F\n");
		}
	printf("Writing the plurals of the nouns...\n");
	FILE *outp;/*defines the plural nouns file*/
	outp=fopen("Plural.txt","w");/*open the file*/
	/*this loop for doing plural of the nouns*/
	for(i=0;i<9;i++){
	make_plural(word[i],plural_noun, v_hard, v_soft );
	fprintf(outp,"%s\n",plural_noun);
	}
	fclose(outp);/*close the file*/
	
	return 0;
	
}