CR - 2021 CPP
CR - 2021 CPP
Université Cadi Ayyad, Faculté des Science Semlalia, Département de Physique, Filière SMP–S4
Contrôle de rattrapage- EPR Théorique - Informatique, Durée : 1h30
Session Printemps 2021
Consignes
Vous avez droit à une et une seule copie. Lire attentivement l’énoncé de la question avant de NOIRCIR ( ) la bonne réponse. Utiliser un stylo bleu ou un stylo
noir. Une mauvaise réponse fait perdre des points. L’absence de réponse vaut 0 point. Pour des raisons d’organisation, nous avons omis volontairement dans chaque
question, l’entête suivante:
#include<iostream>
using namespace std;
Question 1 ( 1 pt ) Erreur 0 10 20 30
int main() 8.92 10 20 30 40
{
int k=1 , x=2 , y=5, z; 10.58 12.33 Question 10 ( 2 pt )
z = k++ ∗ x + y ; int main()
cout « ”z=”« z « endl; Question 6 ( 3 pt ) {
} int main() int A[5],i;
{ for(i=0;i<5;i++)
c=14 c=9 c=7 int a=10, b=20 ; {
int &x=a , &y=b ; A+i=i∗10 ;
Question 2 ( 2 pts ) x=a+y++ ; cout«∗(A+i)«”\t”;
int main() cout«a«”;”«b«endl; }
{ } }
int x=1, y=0 ; bool p ; 10 20 30 40 50
p = x++ && ++y ; Erreur 10 ; 20
cout«p«”\t”«x«”\t”«y ; 31 ; 21 Erreur
} 10 20 30 40
30 ; 20 30 ; 21
1 1 1 0 10 20 30 40
Question 7 ( 2 pt )
1 2 1 int main() Question 11 ( 3 pt )
{ int main()
0 2 1 int a=5, b=10 ; {
char c; c=’+’ ; int ∗a,∗b,∗maxi;
0 2 0 ∗a=5 , ∗b=10 ;
switch(c)
Question 3 ( 1 pt ) { if(∗a>∗b) maxi=b ;
int main() case ’-’ : cout«a-b«’\t’ ; else maxi=b ;
{ case ’+’ : cout«a+b«’\t’ ; cout«maxi«endl;
int x=2 , y=1 , z=3; case ’∗’ : cout«a∗b«’\t’ ; }
z = y =++x ; case ’/’ : cout«a/b«’\t’ ; On donne: &a=0x6ffe1c &b=0x6ffe18 &maxi=0x6ffe10
cout « x«”\t”« y «”\t”«z; } 10 N’affiche rien
} }
0x6ffe1c 0x6ffe18
3 3 3 -5 15 50 0.5 15 50 0.5
Question 12 ( 3 pt )
2 3 3 15 15 50 0 int main()
2 1 3 {
Question 8 ( 3 pt ) float a=2,b=4,x,h=a/b;
Question 4 ( 2 pt ) int main() for( ;a<b; )
int main() { {
{ int a=10,b=20,c=30; a+=h ; cout«a«”\t”;
int x=2, y=5, p=7 ; int &x=a, &y=b, x=a+y; }
p = (x++ , y++) ; int &x=c, ++c ; }
cout«p ; cout«a«”;”«b«”;”«c«endl;
} } Erreur
2 3 3.5 4
Erreur 30;20;30
5 2 6 3 boucle infini
30;20;31
2.5 3 3.5 4
Question 5 ( 3 pt ) 20;10;30 10;20;30
2 2.5 3 3.5
float devise (float euro, float dollar=0,float li_st=0)
{ Question 9 ( 2 pt ) Question 13 ( 2 pt )
float dirham=0; int main() int main()
dirham+=euro∗10.58; { {
dirham+=dollar∗8.92 ; int A[5]={10,20,30,40},i; int A[5]={10,20,30,40},i;
dirham+=li_st∗12.33 ; return dirham ; for(i=0;i<5;i++) for(i=0;i<5;i++)
} cout«A[i]«”\t” ; cout«∗A+i«”\t” ;
int main() } }
{ Erreur
cout«devise(1)«endl; 10 11 12 13 14
} 10 20 30 40 0 10 20 30 40 0
y y
y +1/2/59+ y
10 20 30 40 Question 21 ( 1 pt ) Question 27 ( 1 pt )
int main() int main()
Erreur { {
Question 14 ( 2 pts ) int a = 10; int a=5, ∗P ; P=&a ;
int main() do cout«a«”\t”«P«endl;
{ { a-- ; cout« ”\t”«a ; } }
int B[6]={5,1,4,8,3,2}, i ; while ( a >1); L’adresse de a est : 0x69fefc
for(i=1;i<=5;i++) } L’adresse de P est : 0x69fef8
cout«B[i]«”\t”; 5 0x69fefc
} 9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1 0 5 5
1 4 8 3
9 8 7 6 5 4 3 2 5 0x69fef8
1 4 8 3 2
Question 28 ( 2 pts )
1 4 8 Question 22 ( 1 pt ) int main()
int main() {
5 1 4 8 3 2 { int a= 2, b= 5 , ∗p1, ∗p2;
int a = 0; p1=&a ; p2=&b ; p1=p2;
Question 15 ( 2 pts ) while ( a < 8)
int main() cout «∗p1«”\t”«∗p2«endl;
{ cout« ”\t”«a; a++; } }
{ }
int B[6]={1,9,7,5,3,8}, i ;
for(i=5;i>=0;i=i-2) 5 2
0 1 2 3 4 5 6 7
cout«B[i]«”\t”; 5 5
} 1 2 3 4 5 6 7 8
2 5
0 1 2 3 4 5 6
8 5 9 2 2
8 3 5 Question 23 ( 1 pt )
void affiche(int a) ---------------- Début de l’exercice ---------------
1 7 3 Exercice
{
1 9 7 a=5;
} int main()
Question 16 ( 1 pt ) {
int main() int main()
{ int x = 5 , y = 3 , z=1 , a=7 ,∗p,k;
{ cout « &x « ’\t’ « &y « ’\t’ « &z « ’\t’ « &a «
int B[5]={1,3,5,7,9}; int a=2 ;
affiche(a); endl;
B++ ; cout«B ; for(p=&a,k=1;k<4;k++)
} cout«a«endl;
} {
∗p = 2 ∗ k + 1;
Erreur 1 0x22fef4 p++;
5 Erreur 2
}
Question 17 ( 1 pt ) cout « x « ’\t’ « y « ’\t’ « z « ’\t’ « a « endl;
int main() Question 24 ( 3 pts )
void fonction (int a , int b) cout«p-&z«’\t’ « y-k «endl;
{ ∗p = 0 ;
int B[]={7,5,3,0,1} ; {
a--; ++b; ∗(p − 1) = 2;
cout«∗B-1; cout « x « ’\t’ « y « ’\t’ « z « ’\t’ « a « endl;
} }
int main() p-=x;
Erreur { ∗p = a;
int a= 3 , b= 7; ∗(p − 1) = k ;
Valeur affichée est incorrecte fonction (a , b); cout « x « ’\t’ « y « ’\t’ « z « ’\t’ « a « endl;
6 cout«a«’\t’«b; }
} Question 29 ( 2 pts )
Question 18 ( 2 pts ) 2 8
int main() 0x69fec8 0x69fecc 0x69fed0 0x69fed4
{ 0 0 0x69fed4 0x69fed0 0x69fecc 0x69fec8
int x=0 , y=2 ; 3 8
if (x>5 && (++y)<1 ) x=4; 0x69fed0 0x69fed4 0x69fecc 0x69fec8
else x=6; 3 7 0x69fed0 0x69fed0 0x69fec8 0x69fecc
cout«”y = ”«y«endl ; 2 7
} Question 30 ( 2 pts )
Question 25 ( 3 pt ) 5 7 3 5
y=1 y=3 y=2 y=4 int main()
{ 5 5 7 3
Question 19 ( 3 pts ) int a=3, b=2, c=1 ; 7 5 5 3
int main() c+= b ∗= ++a/=2 ;
cout«a«”\t”«b«”\t”«c«endl; ; 5 7 5 3
{
int a = 1; } Question 31 ( 2 pts )
do
{ a++; cout«”\t”«a ;} 2 2 3 2 3
while(a==2 && a<5); 3 2 1 2 2
}
4 8 9 -3 -2
Boucle infini 2 4 5 3 2
2 3 2 4 4 -3 3
1 2 3 4 2 -3
2 3 4 5 Question 26 ( 3 pts )
int main() Question 32 ( 2 pts )
2 { 0 2 5 3
int B[]={1,3,5,7,9},∗p1,∗p2;
Question 20 ( 2 pts ) p1=&B[1]; p2=p1+B[0]; 2 0 5 3
int main() cout« p1 «’\t’ « p2 «”\t”« ∗p2-∗p1 «endl;
{ 3 5 2 0
}
int a ; Dans les réponses proposées, les quantités p1 et p2 sont 0 2 3 5
for( a = 1 ; a<10 ; a++) ; exprimés sous forme de B+i au lieu de 0x…
cout« ”\t”«a ; Question 33 ( 2 pts )
} 3 7 2 4 3 5 3
1 2 3 4 5 6 7 8 9 B+1 B+2 3 4 3 3 5
9 3 5 2 3 4 3 5
1 2 3 4 5 6 7 8 9 10 B+1 B+2 2 3 4 5 3
10 B+1 B+3 4 ------------------ Fin de l’exercice --------------
y y
y +2/1/58+ y
Université Cadi Ayyad, Faculté des Science Semlalia, Département de Physique, Filière SMP–S4
Contrôle de rattrapage- EPR Théorique - Informatique, Durée : 1h30
Session Printemps 2021
Consignes
Vous avez droit à une et une seule copie. Lire attentivement l’énoncé de la question avant de NOIRCIR ( ) la bonne réponse. Utiliser un stylo bleu ou un stylo
noir. Une mauvaise réponse fait perdre des points. L’absence de réponse vaut 0 point. Pour des raisons d’organisation, nous avons omis volontairement dans chaque
question, l’entête suivante:
#include<iostream>
using namespace std;
y y
y +2/2/57+ y
y y
y +3/1/56+ y
Université Cadi Ayyad, Faculté des Science Semlalia, Département de Physique, Filière SMP–S4
Contrôle de rattrapage- EPR Théorique - Informatique, Durée : 1h30
Session Printemps 2021
Consignes
Vous avez droit à une et une seule copie. Lire attentivement l’énoncé de la question avant de NOIRCIR ( ) la bonne réponse. Utiliser un stylo bleu ou un stylo
noir. Une mauvaise réponse fait perdre des points. L’absence de réponse vaut 0 point. Pour des raisons d’organisation, nous avons omis volontairement dans chaque
question, l’entête suivante:
#include<iostream>
using namespace std;
y y
y +3/2/55+ y
y y
y +4/1/54+ y
Université Cadi Ayyad, Faculté des Science Semlalia, Département de Physique, Filière SMP–S4
Contrôle de rattrapage- EPR Théorique - Informatique, Durée : 1h30
Session Printemps 2021
Consignes
Vous avez droit à une et une seule copie. Lire attentivement l’énoncé de la question avant de NOIRCIR ( ) la bonne réponse. Utiliser un stylo bleu ou un stylo
noir. Une mauvaise réponse fait perdre des points. L’absence de réponse vaut 0 point. Pour des raisons d’organisation, nous avons omis volontairement dans chaque
question, l’entête suivante:
#include<iostream>
using namespace std;
Question 1 ( 1 pt ) 3 8 2
int main()
{ 3 7 Boucle infini
int x=2 , y=1 , z=3; 0 0 1 2 3 4
z = y =++x ;
cout « x«”\t”« y «”\t”«z; 2 8 2 3 4 5
} Question 6 ( 3 pt ) Question 10 ( 1 pt )
int main() int main()
2 1 3 { {
2 3 3 int a=3, b=2, c=1 ; int a = 0;
c+= b ∗= ++a/=2 ; while ( a < 8)
3 3 3 cout«a«”\t”«b«”\t”«c«endl; ; { cout« ”\t”«a; a++; }
Question 2 ( 2 pts ) } }
int main()
{ 2 4 4 0 1 2 3 4 5 6
int x=1, y=0 ; bool p ; 2 2 3 1 2 3 4 5 6 7 8
p = x++ && ++y ;
cout«p«”\t”«x«”\t”«y ; 3 2 1 0 1 2 3 4 5 6 7
} 2 4 5 Question 11 ( 2 pts )
4 8 9 int main()
1 2 1 {
0 2 1 Question 7 ( 1 pt ) int a ;
void affiche(int a) for( a = 1 ; a<10 ; a++) ;
1 1 1 cout« ”\t”«a ;
{
0 2 0 a=5; }
}
Question 3 ( 1 pt ) int main() 9
int main() { 10
{ int a=2 ;
int k=1 , x=2 , y=5, z; affiche(a); 1 2 3 4 5 6 7 8 9
z = k++ ∗ x + y ; cout«a«endl;
cout « ”z=”« z « endl; 1 2 3 4 5 6 7 8 9 10
}
}
Erreur 2 5 Question 12 ( 3 pts )
c=9 c=14 c=7 int main()
{
Question 4 ( 2 pt ) Question 8 ( 1 pt ) int B[]={1,3,5,7,9},∗p1,∗p2;
int main() int main() p1=&B[1]; p2=p1+B[0];
{ { cout« p1 «’\t’ « p2 «”\t”« ∗p2-∗p1 «endl;
int x=2, y=5, p=7 ; int a = 10; }
p = (x++ , y++) ; do Dans les réponses proposées, les quantités p1 et p2 sont
cout«p ; { a-- ; cout« ”\t”«a ; } exprimés sous forme de B+i au lieu de 0x…
} while ( a >1);
} B+1 B+2 3
2 3 5 6 3 7 2
9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1 0 3 5 2
Question 5 ( 3 pts )
void fonction (int a , int b) B+1 B+2 2
9 8 7 6 5 4 3 2
{ B+1 B+3 4
a--; ++b; Question 9 ( 3 pts )
} int main() Question 13 ( 2 pts )
int main() { int main()
{ int a = 1; {
int a= 3 , b= 7; do int a= 2, b= 5 , ∗p1, ∗p2;
fonction (a , b); { a++; cout«”\t”«a ;} p1=&a ; p2=&b ; p1=p2;
cout«a«’\t’«b; while(a==2 && a<5); cout «∗p1«”\t”«∗p2«endl;
} } }
2 7 2 3 5 2
y y
y +4/2/53+ y
2 5 { 1 4 8 3
2 2 float dirham=0;
dirham+=euro∗10.58; 1 4 8 3 2
5 5 dirham+=dollar∗8.92 ; 5 1 4 8 3 2
Question 14 ( 1 pt ) dirham+=li_st∗12.33 ; return dirham ;
} Question 27 ( 1 pt )
int main() int main()
{ int main()
{ {
int a=5, ∗P ; P=&a ; int B[5]={1,3,5,7,9};
cout«a«”\t”«P«endl; cout«devise(1)«endl;
} B++ ; cout«B ;
} }
L’adresse de a est : 0x69fefc
L’adresse de P est : 0x69fef8 10.58 0
Erreur 1 0x22fef4
5 0x69fef8 8.92
5 0x69fefc 12.33 Erreur Question 28 ( 2 pts )
5 5 int main()
Question 21 ( 3 pt ) {
int main() int x=0 , y=2 ;
Question 15 ( 2 pt ) {
int main() if (x>5 && (++y)<1 ) x=4;
int a=10, b=20 ; else x=6;
{ int &x=a , &y=b ;
int A[5]={10,20,30,40},i; cout«”y = ”«y«endl ;
x=a+y++ ; }
for(i=0;i<5;i++) cout«a«”;”«b«endl;
cout«A[i]«”\t” ; } y=4 y=1 y=3 y=2
}
10 ; 20 30 ; 20
10 20 30 ---------------- Début de l’exercice ---------------
30 ; 21
Erreur Exercice
Erreur 31 ; 21
10 20 30 40 int main()
10 20 30 40 0 Question 22 ( 3 pt ) {
int main() int x = 5 , y = 3 , z=1 , a=7 ,∗p,k;
Question 16 ( 2 pt ) {
int main() cout « &x « ’\t’ « &y « ’\t’ « &z « ’\t’ « &a «
int ∗a,∗b,∗maxi; endl;
{ ∗a=5 , ∗b=10 ;
int A[5]={10,20,30,40},i; for(p=&a,k=1;k<4;k++)
if(∗a>∗b) maxi=b ; {
for(i=0;i<5;i++) else maxi=b ;
cout«∗A+i«”\t” ; ∗p = 2 ∗ k + 1;
cout«maxi«endl; p++;
} } }
10 20 30 40 0 On donne: &a=0x6ffe1c &b=0x6ffe18 &maxi=0x6ffe10 cout « x « ’\t’ « y « ’\t’ « z « ’\t’ « a « endl;
Erreur cout«p-&z«’\t’ « y-k «endl;
10 0x6ffe1c ∗p = 0 ;
10 11 12 13 14 N’affiche rien 0x6ffe18 ∗(p − 1) = 2;
10 20 30 40 cout « x « ’\t’ « y « ’\t’ « z « ’\t’ « a « endl;
Question 23 ( 3 pt ) p-=x;
Question 17 ( 2 pt ) int main() ∗p = a;
int main() { ∗(p − 1) = k ;
{ float a=2,b=4,x,h=a/b; cout « x « ’\t’ « y « ’\t’ « z « ’\t’ « a « endl;
int A[5],i; for( ;a<b; ) }
for(i=0;i<5;i++) {
{ a+=h ; cout«a«”\t”; Question 29 ( 2 pts )
A+i=i∗10 ; }
cout«∗(A+i)«”\t”; } 0x69fec8 0x69fecc 0x69fed0 0x69fed4
} 0x69fed4 0x69fed0 0x69fecc 0x69fec8
} 2 2.5 3 3.5
0x69fed0 0x69fed4 0x69fecc 0x69fec8
Erreur boucle infini
2.5 3 3.5 4 0x69fed0 0x69fed0 0x69fec8 0x69fecc
10 20 30 40 50
10 20 30 40 2 3 3.5 4 Question 30 ( 2 pts )
0 10 20 30 40 Erreur 5 7 5 3
Question 18 ( 2 pt ) Question 24 ( 2 pts ) 5 5 7 3
int main() int main()
{ { 7 5 5 3
int a=5, b=10 ; int B[6]={1,9,7,5,3,8}, i ; 5 7 3 5
char c; c=’+’ ; for(i=5;i>=0;i=i-2)
switch(c) cout«B[i]«”\t”; Question 31 ( 2 pts )
{ }
case ’-’ : cout«a-b«’\t’ ; 2 -3
8 3 5
case ’+’ : cout«a+b«’\t’ ; 3 2
case ’∗’ : cout«a∗b«’\t’ ; 1 7 3
case ’/’ : cout«a/b«’\t’ ; -3 3
1 9 7
} 2 2
} 8 5 9
2 3
Question 25 ( 1 pt )
15 15 50 0.5 int main() -3 -2
-5 15 50 0.5 15 50 0 {
int B[]={7,5,3,0,1} ; Question 32 ( 2 pts )
Question 19 ( 3 pt ) cout«∗B-1; 2 0 5 3
int main() }
{ 3 5 2 0
int a=10,b=20,c=30; Valeur affichée est incorrecte
0 2 5 3
int &x=a, &y=b, x=a+y; Erreur
int &x=c, ++c ; 0 2 3 5
cout«a«”;”«b«”;”«c«endl; 6
} Question 26 ( 2 pts ) Question 33 ( 2 pts )
int main() 4 3 3 5
20;10;30 10;20;30 {
30;20;30 int B[6]={5,1,4,8,3,2}, i ; 3 4 5 3
for(i=1;i<=5;i++) 4 3 5 3
30;20;31 Erreur cout«B[i]«”\t”;
} 3 4 3 5
Question 20 ( 3 pt )
float devise (float euro, float dollar=0,float li_st=0) 1 4 8 ------------------ Fin de l’exercice --------------
y y