ParsX.com
پذیرش پروژه از دانشجویی ... تا سازمانی 09376225339
 
   ProfileProfile   Log in to check your private messagesLog in to check your private messages  |  FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups Log inLog in   RegisterRegister 

آخرین تمرین ...

 
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming
View previous topic :: View next topic  
Author Message
arash
مدير بخش سي
مدير بخش سي


Joined: 27 Nov 2004
Posts: 1232
Location: www.parsx.com

PostPosted: Mon Jan 17, 2005 2:51 pm    Post subject: آخرین تمرین ... Reply with quote

مثال : برنامه ای بنویسید و در آن یک لیست 50 تایی از دانشجویان با مشخصات فوق (نام ، شماره دانشجویی ، تلفن ، معدل و سال تولد ) تعریف کنید
الف ) تابعی بنویسید که تعداد و اطلاعات دانشجویان را از ورودی بخواند .
ب ) تابعی بنویسید که یک عدد صحیح بگیرد ( به عنوان پارامتر ) و دانشجویی که اندیس آن i است در خروجی بنویسد.
ج ) تابعی بنویسید که یک رشته را از ورودی گرفته و معدلهای دانشجویانی که نامشان برابر رشته است برگرداند .
د ) تابعی بنویسید که یک رشته از ورودی بگیرد تعداد دانشجویانی که پیش شماره تلفن آنها برابر رشته مزبور است برگرداند.
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
      {
        char name[50];
        char tel[20];
        char number[12];
        int ave;
        int bornyear;
      }str[50];
int i,j;
void sget(void);
void printi(void);
void Name(void);
void Tel(void);
main()
{
strcpy(str[1].name,"ali");
/*alef*/   sget();
/*be*/     printi();
/*jem*/    Name();
/*dal*/    Tel();
      getch();
      return 0;
}
/********************************************************/
void sget(void)
{
   do{
   clrscr();
   printf("\n\n\t\t Enter a number of student :");
   scanf("%d",&j);
   }while((j<0)||(j>50));
   for(i=0;i<j;i++)
   {
    clrscr();
    gotoxy(5,10);
    printf("\n\t Enter a name of student :");
    scanf("%s",str[i].name);
    printf("\n\t Enter ID code of student(%d) :",i+1);
    scanf("%s",str[i].number);
    printf("\n\t Enter the phone number of student(%d) :",i+1);
    scanf("%s",str[i].tel);
    printf("\n\t Enter the Average of student(%d) :",i+1);
    scanf("%d",&str[i].ave);
    printf("\n\t Enter the born year of student(%d) :",i+1);
    scanf("%d",&str[i].bornyear);
   }
}
/************************************************************/
void printi(void)
{
    printf("\n\n\n Enter i : ");
    scanf("%d",&i);
    i--;
    printf("\n\n the name of student(%d) is %s",i+1,str[i].name);
}
/*********************************************************/
void Name(void)
{
    int ii=-1;
    char ss[50];
    printf("\n\n Enter name of student :");
    scanf("%s",ss);
    for(i=0;i<j;i++)
    if(!strcmp(ss,str[i].name)){
            ii=0;
            printf("\n the average of student is %d"
            ,str[ii].ave);
                }
    if(ii)printf("\n\t\t\t NOT FOUND !!!");
}
/********************************************************/
void Tel(void)
{
    int ii=1;
    char ss[4],oo[4];
    char *s;
    printf("\n\n Enter student local code tel:");
    scanf("%s",ss);
    for(i=0;i<j;i++)
    {
    s=str[i].tel;
    *oo=*s;
    *(oo+1)=*(s+1);
    *(oo+2)=*(s+2);
    oo[3]=0;
    if(!strcmp(ss,oo)){
            ii=0;
            printf("\n the local code of student is %s"
            ,str[ii].name);
                }
    }
    if(ii)printf("\n\t\t\t NOT FOUND !!!");
}



لازم به یادآوری نیست که [str[50 از نوع سراسری تعریف شده و در متغییر s ادرس اولین شماره هر دانشجو ریخته می شود و ...
اگه یکم سنگین شد به بزرگواری خودتون ببخشید .
سوالی بود در خدمتم .
خیلی چاکریم Laughing Laughing Laughing .
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Mon Jan 17, 2005 5:21 pm    Post subject: Reply with quote

ايول ...
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Mon Jan 17, 2005 5:49 pm    Post subject: debug Reply with quote

void Tel(void)
.
.
.
    char *s;
    s=str[i].tel;

اين يه تيكه برام قابل فهم نيست آرش ؟!
يه متغير s از نوع اشاره گر به كاراكتر تعريف كردي ...
بعد شماره تلفني كه احتمالا چند كاراكتر (كمتر از 12) را ميريزي توش ؟!
بازش كن آرش جان ...
مرصي .
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Mon Jan 17, 2005 6:06 pm    Post subject: Reply with quote

راستي اون برنامه strstr كه گفتي اجرا نشد . كد رو اشتباهي paste كرده بودم . الان درست شده ...
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Mon Jan 17, 2005 8:51 pm    Post subject: Reply with quote

برنامه رو هم فهميدم چي شد !
دمت گرم جالب بود .
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Mon Jan 17, 2005 10:22 pm    Post subject: يه راه حل ديگه ... Reply with quote

#include <stdio.h>
#includ <stdlib>
#include <conio.h>
struct reza {
      char  name [20];
      char  year[10];
      flout  Ave ;
      char  tel [10];
            } stu [100];
;
void   my_get  (void);
void   my_display  (void);
void   my_Ave  (void);
void   my_search  (void);
void   my_all  (void);
;
main()
{
  my_get ();
  my_display ();
  my_ave ();
  my_search ();
  my_all ();
}
                   /*define function*/
void my_get (void )
{
   for (i=0 ; i<100 ; i++)
   printf ("pleas enter: name, year, ave ,tel")
   scanf ("%s%s%f%s",stu[i].name,stu[i].year,&stu[i].ave,stu[i].tel);
}
----------------------------------------------------------------------
                  /*define function*/
void my_display (void)
{
   int n;
   printf("enter a number");
   scanf ("%d",&n);
   printf ("name:%s,year:%s,average:%f,telephon:%s",stu[n].name
            ,stu[n].year,stu[n].ave,stu[n].tel);
}
------------------------------------------------------------------------
                  /*define function*/
void my_Ave (void)
{
     flout count=0;
     int n=1;
     printf("enter a name");
     gets(s);
     for(i=0 ; i<100 ; i++)
         {
            if (strcmp(stu[i].name,s)==0)
           printf("%f",stu[i].ave);
           count+=stu[i].ave
           n++
         }
    printf("%f/%d",count,n);
}
---------------------------------------------
                   /* define function*/
void my_search (void)
{
char all_name [1000];
char temp [10];
char s[10];
printf("enter a tel number");
gets(s);
for (j=0 ; j<100 ; j++)
  {
    strcpy(temp,stu[j].tel);
        {
           for (i=0 ; i<4 ; i++)
           if(s[i]==temp[i])
           strcpy (all_name,temp)
        }
   puts(all_name);
  }
}
--------------------------------------------
                   /* define function*/
void my_all (void) 
{
     for(i=0 ; i<100 ; i++)
     printf("%f",stu[i].ave];
}
\\\\\\\\\\\\ FINISH ////////               
 
 
Back to top
arash
مدير بخش سي
مدير بخش سي


Joined: 27 Nov 2004
Posts: 1232
Location: www.parsx.com

PostPosted: Tue Jan 18, 2005 12:28 am    Post subject: Reply with quote

بقولی ترکندیم دیگه نه !!!
اقا خسته نباشی با حال بود ... Wink
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Tue Jan 18, 2005 12:56 pm    Post subject: Reply with quote

عمرا هيچ کس فكر نميكرد امتحان اينطوري باشه !
Back to top
arash
مدير بخش سي
مدير بخش سي


Joined: 27 Nov 2004
Posts: 1232
Location: www.parsx.com

PostPosted: Tue Feb 22, 2005 6:20 am    Post subject: Reply with quote

vahid wrote:
عمرا هيچ کس فكر نميكرد امتحان اينطوري باشه !

عمرا هيچ کس فكر نميكرد نمرها اينطوري باشه !
Back to top
Display posts from previous:   
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming All times are GMT + 3.5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum