A7.pdf

‫ﻣﺒﺎﻧﯽ ﺑﺮﻧﺎﻣﻪﺳﺎﺯﯼ‬
‫ﻧﯿﻢﺳﺎﻝ ﺍﻭﻝ ‪۹۳-۹۴‬‬
‫ﺩﺍﻧﺸﮕﺎﻩ ﺻﻨﻌﺘﯽ ﺷﺮ ﯾﻒ‬
‫ﻣﺪﺭﺱ‪:‬ﺍﻣﯿﺪ ﻏﯿﺒﯽ‬
‫ﺩﺍﻧﺸﮑﺪﻩﯼ ﻣﻬﻨﺪﺳﯽ ﮐﺎﻣﭙﯿﻮﺗﺮ‬
‫ﺗﻤﺮ ﯾﻦ ‪۷‬‬
‫ﺍﺷﺎﺭﻩﮔﺮ‪ ،‬ﺭﺷﺘﻪ ﻭ ﺁﺷﻨﺎﯾﯽ ﺍﻭﻟﯿﻪ ﺑﺎ ‪ struct‬ﻭ ‪class‬‬
‫ﻣﻬﻠﺖ ﺍﺭﺳﺎﻝ ‪ ۵ :‬ﺩﯼ‬
‫ﺑﻪ ﻣﻮﺍﺭﺩ ﺯﯾﺮ ﺗﻮﺟﻪ ﮐﻨﯿﺪ‪:‬‬
‫• ﺣﺘﻤﺎ ﺩﺭ ﺍﺭﺳﺎﻝ ﻓﺎﯾﻞ ﺑﺮﻧﺎﻣﻪﻫﺎ ﺑﻪ ﻧﺎﻡ ﻓﺎﯾﻞ ﻭ ﻓﺮﻣﺖ ﻭﺭ ﻭﺩﯼ ﻭ ﺧﺮﻭﺟﯽﻫﺎ ﺗﻮﺟﻪ ﺷﻮﺩ‪ .‬ﺩﺭ ﺻﻮﺭﺕ ﺍﺷﺘﺒﺎﻩ‬
‫ﺩﺭ ﻧﺤﻮﻩﯼ ﺩﺭ ﯾﺎﻓﺖ ﻭﺭ ﻭﺩﯼ ﻭ ﭼﺎﭖ ﺧﺮ ﻭﺟﯽ‪ ،‬ﻧﻤﺮﻩﺍﯼ ﺑﻪ ﺷﻤﺎ ﺗﻌﻠﻖ ﻧﺨﻮﺍﻫﺪ ﮔﺮﻓﺖ‪.‬‬
‫• ﺩﺭ ﺗﻤﺎﻣﯽ ﺳﻮﺍﻻﺕ‪ ،‬ﺣﺪﺍﮐﺜﺮ ﻃﻮﻝ ﺭﺷﺘﻪﯼ ﻭﺍﺭﺩ ﺷﺪﻩ ﺭﺍ ‪ ۱۰۰۰‬ﮐﺎﺭﺍﮐﺘﺮ ﺩﺭ ﻧﻈﺮ ﺑﮕﯿﺮ ﯾﺪ‪.‬‬
‫• ﻫﻢﻓﮑﺮﯼ ﻭ ﻫﻢﮐﺎﺭﯼ ﺩﺭ ﭘﺎﺳﺦ ﺑﻪ ﺗﻤﺮ ﯾﻨﺎﺕ ﺍﺷﮑﺎﻟﯽ ﻧﺪﺍﺭﺩ ﻭﻟﯽ ﭘﺎﺳﺦ ﺍﺭﺳﺎﻟﯽ ﺣﺘﻤﺎً ﺑﺎﯾﺪ ﺗﻮﺳﻂ ﺧﻮﺩ‬
‫ﺷﺨﺺ ﻧﻮﺷﺘﻪ ﺷﺪﻩ ﺑﺎﺷﺪ‪ .‬ﮐﺎﻣﻨﺖ ﮐﺮﺩﻥ ﻧﺎﻡ ﺍﻓﺮﺍﺩﯼ ﮐﻪ ﺑﺎ ﺁﻥﻫﺎ ﻫﻢﻓﮑﺮﯼ ﺩﺍﺷﺘﻪﺍﯾﺪ‪ ،‬ﻭﺍﺟﺐ ﺍﺳﺖ!‬
‫• ﻣﺒﻨﺎﯼ ﺩﺭﺱ‪ ،‬ﺍﻋﺘﻤﺎﺩ ﺑﺮ ﭘﺎﺳﺦ ﺍﺭﺳﺎﻟﯽ ﺍﺯ ﺳﻮﯼ ﺷﻤﺎﺳﺖ؛ ﺑﻨﺎﺑﺮﺍﯾﻦ ﺍﺭﺳﺎﻝ ﭘﺎﺳﺦ ﺩﺭ ﺳﺎﻣﺎﻧﻪﯼ ﺩﺍﻭﺭﯼ ﺑﻪ‬
‫ﺍﯾﻦ ﻣﻌﻨﺎﺳﺖ ﮐﻪ ﭘﺎﺳﺦ ﺁﻥ ﺗﻤﺮ ﯾﻦ‪ ،‬ﺗﻮﺳﻂ ﺷﻤﺎ ﻧﻮﺷﺘﻪ ﺷﺪﻩ ﺍﺳﺖ‪ .‬ﺩﺭ ﺻﻮﺭﺕ ﺗﻘﻠﺐ ﻭ ﯾﺎ ﺍﺛﺒﺎﺕ ﻋﺪﻡِ ﻧﻮﺷﺘﺎﺭ‬
‫ﭘﺎﺳﺦِ ﺣﺘﯽ ﯾﮏ ﺳﻮﺍﻝ ﺍﺯ ﺗﻤﺮ ﯾﻦ‪ ،‬ﻧﻤﺮﻩﯼ ﺁﻥ ﺗﻤﺮ ﯾﻦ ﺑﻪ ﻃﻮﺭ ﮐﺎﻣﻞ ﺑﺮﺍﯼ ﻫﺮ ﺩﻭ ﻃﺮﻑِ ﺗﻘﻠﺐﮔﯿﺮﻧﺪﻩ ﻭ‬
‫ﺗﻘﻠﺐﺩﻫﻨﺪﻩ ﺑﺮﺍﺑﺮ ﺻﻔﺮ ﻗﺮﺍﺭ ﺩﺍﺩﻩ ﺧﻮﺍﻫﺪ ﺷﺪ‪.‬‬
‫• ﻣﻬﻠﺖ ﺍﺭﺳﺎﻝ ﻓﺎﯾﻞﻫﺎ ﺗﺎ ﺳﺎﻋﺖِ ‪ ۲۳:۵۹‬ﺗﺎﺭ ﯾﺦِ ﮔﻔﺘﻪ ﺷﺪﻩ ﺍﺳﺖ‪ .‬ﭘﺲ ﺍﺯ ﮔﺬﺷﺖِ ﺣﺘﯽ ﯾﮏ ﺛﺎﻧﯿﻪ ﺍﺯ ﺍﯾﻦ‬
‫ﺯﻣﺎﻥ‪ ،‬ﺗﺎ ﺳﻪ ﺭ ﻭﺯ ﻧﻤﺮﻩﯼ ﺷﻤﺎ ﺑﺎ ﺿﺮ ﯾﺐ ‪ ۰.۶‬ﻭ ﭘﺲ ﺍﺯ ﺁﻥ ﺗﺎ ﯾﮏ ﻫﻔﺘﻪ‪ ،‬ﺑﺎ ﺿﺮ ﯾﺐ ‪ ۰.۳‬ﻣﺤﺎﺳﺒﻪ ﺧﻮﺍﻫﺪ‬
‫ﺷﺪ‪ .‬ﺍﺭﺳﺎﻝ ﺑﺎ ﺗﺄﺧﯿﺮ ﺑﯿﺶ ﺍﺯ ﯾﮏ ﻫﻔﺘﻪ‪ ،‬ﻣﺠﺎﺯ ﻧﯿﺴﺖ‪.‬‬
‫• ﻫﺮﮔﻮﻧﻪ ﺳﻮﺍﻝ ﻣﺮﺑﻮﻁ ﺑﻪ ﺗﻤﺮﯾﻦﻫﺎ ﺭﺍ ﺑﺎ ﻣﻮﺿﻮﻉ ﻣﻨﺎﺳﺐ ﺩﺭ ﮔﺮ ﻭﻩ ﺩﺭﺱ ﻣﻄﺮﺡ ﮐﻨﯿﺪ‪.‬‬
‫ﮔﺮﻭﻩ ﺗﻤﺮﯾﻦ‬
‫‪۱‬‬
(‫ ﻧﻤﺮﻩ‬۱۰۰)
‫ ﺍﺟﺮﺍﯼ ﻗﻄﻌﻪ ﮐﺪ‬.۱ ‫ﺳﺆﺍﻝ‬
++‫ ﺑﻪ ﺗﻔﺎﻭﺕ ﺯﺑﺎﻥ ﺳﯽ ﻭ ﺳﯽ‬.‫ﻗﻄﻌﻪ ﮐﺪﻫﺎﯼ ﺯﯾﺮ ﺭﺍ ﺍﺟﺮﺍ ﮐﻨﯿﺪ ﻭ ﺧﺮ ﻭﺟﯽ ﺁﻥﻫﺎ ﺭﺍ ﻣﻮﺭﺩ ﺗﺤﻠﯿﻞ ﻗﺮﺍﺭ ﺩﻫﯿﺪ‬
‫ ﺧﺮ ﻭﺟﯽ ﻫﺮ ﻗﻄﻌﻪ ﮐﺪ ﺭﺍ ﺗﺤﻠﯿﻞ ﮐﺮﺩﻩ ﻭ ﺗﺤﻠﯿﻞ ﺧﻮﺩ ﺭﺍ ﺑﻪ ﻃﻮﺭ ﺧﻼﺻﻪ‬.‫ﺩﺭ ﺍﯾﻦ ﺳﻮﺍﻻﺕ ﺗﻮﺟﻪ ﺩﺍﺷﺘﻪ ﺑﺎﺷﯿﺪ‬
.‫ ﺩﺭ ﺟﺎﺝ ﺁﭘﻠﻮﺩ ﮐﻨﯿﺪ‬P DF ‫ﺑﻨﻮﯾﺴﯿﺪ ﻭ ﺩﺭ ﻗﺎﻟﺐ ﯾﮏ ﻓﺎﯾﻞ‬
.‫ﺣﻖ ﺗﺄﻟﯿﻒ ﺑﻌﻀﯽ ﺍﺯ ﮐﺪﻫﺎ ﺑﺮﺍﯼ ﺳﻌﯿﺪ ﻋﻠﯽﺍﮐﺒﺮ ﯾﺎﻥ ﻣﺤﻔﻮﻅ ﺍﺳﺖ‬
# include <iostream >
# include <cmath >
using namespace std;
void Puts(char S[])
{
int i;
for(i=0;S[i]!= NULL;i++)
putchar (S[i]);
putchar ('\n');
}
void Gets(char S[])
{
int i;
for(i=0;(S[i]= getchar ())!= '\n';i++);
S[i]= NULL;
}
int main ()
{
char S[100] ,c;
int n,i;
Gets(S);
Puts(S);
return 0;
}
# include <iostream >
# include <cmath >
using namespace std;
int main ()
{
int a=1,i;
char c='1';
char s[]=" ABCDEFGH ";
cout <<s<<endl;
s[2]=c;
s[5]= NULL;
cout <<s<<endl;
strcpy (s," 1234567 ");
cout <<s<<endl;
s[4]= NULL;
۲
cout <<s<<endl;
a=s[0];
cout <<a<<endl;
return 0;
}
# include <iostream >
# include <cmath >
using namespace std;
void mygets (char s[])
{
int i;
for(i=0;(s[i]= getchar ())!= '\n';i++);
s[i]= NULL;
}
void myputs ( const char s[])
{
int i;
for(i=0;s[i]!= NULL;i++)
putchar (s[i]);
putchar ('\n');
}
int mystrlen (char s[])
{
int i;
for(i=0;s[i]!= NULL;i++);
return i;
}
void mystrcpy (char s1[], const char s2 [])
{
int i;
for(i=0; s2[i]!= NULL;i++)
s1[i]= s2[i];
s1[i]= NULL;
}
void mystrcat (char s1[], const char s2 [])
{
int i,l;
l= mystrlen (s1); // for(l=0; s1[l]!= NULL;l++);
for(i=0; s2[i]!= NULL;i++)
s1[i+l]= s2[i];
s1[i+l]= NULL;
}
int main ()
{
char s1 [20] , s2 [20];
int l;
mystrcpy (s1 ,"Ali");
۳
mystrcat (s1 ," akbarian ");
mystrcpy (s2 ,s1);
mystrcpy (s1 ,"Saeed ");
mystrcat (s1 ," ");
mystrcat (s1 ,s2);
l= mystrlen (s1);
cout <<l<<endl;
myputs (s1);
myputs (s2);
return 0;
}
# include <iostream >
# include <string >
using namespace std;
int main ()
{
int n,i;
string s3 ,s4="456";
char s1 [10]= "123",s2 [10];
n=atoi(s1);
n++;
itoa(n,s2 ,10);
cout <<s2 <<endl;
n=atoi(s4. c_str ());
n++;
itoa(n,s2 ,10);
s3=s2;
cout <<s3 <<endl;
return 0;
}
#include <iostream >
using namespace std;
const int MaxRow =3;
const int MaxCol =4;
void InitArray3 (int a[][ MaxRow ][ MaxCol ],int m,int n,int k)
{
int *p;
p=**a;
for(int i=0;i<m*n*k;i++)
p[i]=i;
}
int main ()
{
int a[2][ MaxRow ][ MaxCol ];
InitArray3 (a,2, MaxRow , MaxCol );
۴
cout <<a[1][1][1] < < endl;
int (*x)[4];
x=a[1];
cout <<x[1][1] < < endl;
cout << sizeof (x)<<endl;
int *y[4];
y [0]=& a [1][1][1];
cout <<*y[0]<< endl;
cout << sizeof (y)<<endl;
return 0;
}
#include <iostream >
using namespace std;
int main ()
{
int *a[2];
cout <<a<<"\t";
cout << sizeof (a)<<"\t";
cout <<a[0]<<"\t";
cout <<&a [0][0];
cout <<endl;
int (*b)[2];
cout <<b<<"\t";
cout << sizeof (b)<<"\t";
cout <<b[0]<<"\t";
cout <<&b [0][0];
return 0;
}
#include < stdio .h>
int main (){
struct node1 {
int count ;
char *word;
struct node1 next;
};
return 0;
}
۵
#include < stdio .h>
int main (){
struct node1 {
int count ;
char *word;
struct node1 *next;
};
return 0;
}
۶
#include <iostream >
# include <stdio .h>
# include <string .h>
using namespace std;
const int MaxStudentNumber =100;
const int MaxStudentNameLen =20;
struct Student
{
int SN;
char Name[ MaxStudentNameLen +1];
char Family [ MaxStudentNameLen +1];
};
void PrintStudent ( const Student S)
{
cout <<endl;
cout <<"ST:"<<S.SN <<endl;
cout <<"Name:"<<S.Name <<endl;
cout <<" FamilyName :"<<S.Family <<endl;
}
int main ()
{
Student Students [ MaxStudentNumber ];
int n;
cin >>n;
for(int i=0;i<n;i++)
cin >>Students [i].SN >>Students [i]. Name >>Students [i]. Family ;
// sort
Student TempStudent ;
for(int i=0;i<n -1;i++)
for(int j=i+1;j<n;j++)
if( strcmp ( Students [i].Name , Students [j]. Name) >0)
{
TempStudent = Students [i];
Students [i]= Students [j];
Students [j]= TempStudent ;
}
for(int i=0;i<n;i++)
PrintStudent ( Students [i]);
return 0;
}
۷
# include <iostream >
using namespace std;
class Student
{
public :
int SN , ProfPN ;
float Marks [5];
char Name [20];
void GetStudent ();
void PrintStudent ();
};
void Student :: GetStudent ()
{
cout <<"SN:"<<endl;
cin >>SN;
cout <<" Professor Personal Number :"<< endl;
cin >>ProfPN ;
cout <<"Name:"<<endl;
cin >>Name;
for(int i=0;i <5;i++)
{
cout <<" Mark ["<<i <<"]:"< < endl;
cin >>Marks [i];
}
}
void Student :: PrintStudent ()
{
cout <<endl;
cout <<"SN:"<<SN <<endl;
cout <<" Professor Personal Number :"<<ProfPN <<endl;
cout <<"Name:"<<Name <<endl;
for(int i=0;i <5;i++)
cout <<"Mark["<<i<<"]:"<<Marks [i]<<endl;
}
void SortStudent ( Student S[], int n)
{
int i,j;
Student temp;
for(i=0;i<n -1;i++)
for(j=i+1;j<n;j++)
if(S[i].SN >S[j].SN)
{
temp=S[i];
S[i]=S[j];
S[j]= temp;
}
}
const int MaxStudentNumber =100;
۸
int main ()
{
Student S1 ,S2 ,S[ MaxStudentNumber ];
int n,i;
cin >>n;
for(i=0;i<n;i++)
S[i]. GetStudent ();
SortStudent (S,n);
for(i=0;i<n;i++)
S[i]. PrintStudent ();
return 0;
}
۹