الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ارجو مساعدتي في تصحيح البرنامج

مغلق
بدأه reem-12 في 30 نوفمبر 2004 · 2 رد · 403 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

write a menu-driven program that permits the following text operations:-

a) Input a line text

B) print a line of text

c) print a count of word lengths,i.e. the total number of words of length 1 which occurred,the number of length 2, and so on. You should allow for word lengths up to 10 letters.

d) print the number of words in each wentence, i.e. the total number of words in sentences are separated by ’ .’

e) print Uppercase letter frequencies

f) print a count of each type of character: digit, space,lowercase,character and uppercase character

Use an array of pointers to functions named AnalyseText to point to the above functions and use the choice made by the user as a subscript of the array for calling each function. The program should offer the user 7 options as follows:

Enter a choice:

Input a line of text 1

2 Print the line of text

3 words length

4 sentences length

5 letter frequencies

6 Count characters types

7 Exit

محاولتي كانت كالتالي لكن وجود الاخطاء فيها،، بالاضافة الى انه يجب ان ادخل الجمله والبرنامج يقوم بالعمل عليها وليس ان تكون موجوده في اصل البرنامج ، اتمنى مساعدتي

اقتباس
# include<stdio.h>

#include<string.h>

#include<ctype.h>

void input(char *line);

void print(char *line);

void CountWords (char *line);

void SentencesLength(char *line);

void Letter_freq(char *line);

void count_char_types(char *line);

int main ()

{

void (*AnalyseText[6])(char* )={input,print,CountWords,SentencesLength,Letter_freq,count_char_types};

int choice;

char line[100]="ITCS 102";

printf("Enter a choice:\n1  Input a line of text\n2  print the line of text\n3  words length\n4  sentences length\n5  letter frequencies\n6  Count characters types\n7  Exit\n");

scanf("%d",& choice);

while(choice>0 && choice<7)

{

(*AnalyseText[choice-1])(line);

  printf("\nEnter a choice:\n1  Input a line of text\n2  print the line of text\n3  words length\n4  sentences length\n5  letter frequencies\n6  Count characters types\n7  Exit\n");

  scanf("%d",& choice);

}

return 0;

}

void input(char *line)

{

printf("Enter a line of text:\n");

gets(line);

gets(line);

}

void print(char *line)

{

puts(line);

}

void CountWords(char *line)

{

int count[10]={0};

char temp[100];

strcpy(temp,line);

char*token=strtok(temp," ");

while(token!=NULL)

{

int length=strlen(token);

if (length<=10)

count[length-1]++;

token=strtok(NULL," ");

}

printf("Words length\n");

for(int j=0;j<10;j++)

{

printf("          lenght %d : %d occurrences", j+1,count[j]);

printf("\n");

}

}

void SentencesLength(char *line)

{

int counter[20]={0};

char temp[100];

strcpy(temp,line);

char*token=strtok(temp,".");

char* word;

char * ptr;

int size=0;

while(token!=NULL)

{

int b=0;

ptr = token;

while(*ptr!='\0')

{

if ( *ptr == ' ')

  {

  if ( isalpha(*(1+ptr)) && isalpha(*(ptr-1)))

  b++;

  else if (*(1+ptr) == ' ')

  {

    while (*(1+ptr) == ' ' && !isalpha(*(1+ptr)) ){ ptr++; }

    b++;

  }

  }

ptr++;

}

counter=b+1;

size++;

token=strtok(NULL,".");

}

printf("Sentences length\n");

for(int m=0;m<size;m++)

{

printf("              Sentence %d : %d words",m+1,counter[m]);

printf("\n");

}

}

void Letter_freq(char*line)

{

char c;

int x,y;

int freq[26]={0};

for (c='A',x=0;c<='Z';c++,x++)

{

  char*ptr=strchr(line,c);

  while(ptr!=NULL)

  {

  freq[x]++;

  ptr=strchr(ptr+1,c);

  }

}

printf("letter frequencies\n");

printf("                  %s%17s\n","Letter","Occurrence");

for( c='A', y=0;y<26;c++,y++)

printf("                  %c%15d\n",c,freq[y]);

}

void count_char_types(char *line)

{

int count_digit=0,count_space=0;

int count_upper=0,count_lower=0;

for(int r=0;line[r]!='\0';r++)

{

  if(isdigit(line[r]))

  count_digit++;

  else if (isupper(line[r]))

  count_upper++;

  else if (islower(line[r]))

  count_lower++;

  else if (isspace(line[r]))

  count_space++;

}

printf("Count characters types\n");

printf("                      Digits        :%d",count_digit);

printf("\n                      Uppercase char:%d",count_upper);

printf("\n                      Lowercase char:%d",count_lower);

printf("\n                      Spaces        :%d",count_space);

}

آمل مساعدتي في القريب العاجل

#2

السلام عليكم و رحمة الله و بركاته

عفوا أخي

أنا دخلت أقرأ الموضوع بغرض المساعدة

لكن أول ما رأيت البرنامج الطويل و الشرح كتير ضاق صدري

و نصيحتي لك قسم الموضوع الي عدة مشاكل و ضع مشكلة واحدة في كل مشاركة

و سامحني

المسلمون ربهم واحد و قبلتهم واحدة و كتابهم واحد

و يقفون يوم الحج الاكبر بملبس متشابه في صعيد واحد

و يصلون الجمعة و الجماعات

كل ذلك و قلوبهم متفرقة

اللهم اجمع شمل المسلمين و ألف بين قلوبهم

أبو المنذر

#3

على العموم مشكور اخوي على مرورك

تحياتي

هذا الموضوع مغلق.

مواضيع مشابهة