برنامه سازی پیشرفته
كتابهاي الكترونيكي درس
#include <iostream.h> void PrintArray(double a[], int n) { cout << "{"; for(int i=0; i<n; i++) { cout << a[i]; if( i != n-1 ) cout << ", "; } cout << "}" << endl; } double ave(double x[], int n) { double s = 0; for(int i=0; i<n; i++) s += x[i]; return s/n; } double variance(double x[], int n) { double xbar = ave(x, n), s = 0; for(int i=0; i<n; i++) s += (x[i]-xbar)*(x[i]-xbar); return s/n; } void main() { double b[10] = {1, 2, 3}; PrintArray( b, 10 ); cout << ave(b, 10) << endl; cout << variance(b, 10) << endl; double y[3] = {4, 6, 8}; PrintArray( y, 3 ); cout << ave(y, 3) << endl; cout << variance(y, 3) << endl; //double y[n]; }
#include <iostream.h> #include <iomanip.h> /* void PrintLn() { cout << "*****" << endl; } void Print2Lines() { PrintLn(); PrintLn(); } void Print3Lines() { PrintLn(); PrintLn(); PrintLn(); } void main() { Print3Lines(); cout << "Hello World!" << endl; Print2Lines(); } //*/ /* void PrintLn(int n) { for(int i=0; i<n; i++) cout << '*'; cout << endl; } void PrintLines(int n) { for(int i=0; i<n; i++) PrintLn(50); } void main() { PrintLines(14); cout << "Hello World!" << endl; PrintLines(5); } //*/ /* void PrintLn(int n, char ch) { for(int i=0; i<n; i++) cout << ch; cout << endl; } void PrintLines(int n, int m, char ch) { for(int i=0; i<n; i++) PrintLn(m, ch); } void main() { PrintLines(8, 12, '+'); cout << "Hello World!" << endl; PrintLines(5, 16, '='); } //*/ /* void PrintLn(int n, char ch) { for(int i=0; i<n; i++) cout << ch; cout << endl; } void main() { int n; cin >> n; char ch = 97; for(int i=1; i<=n; i++) { PrintLn(i, ch); ch++; } } //*/ int fact(int n) { int f = 1; for(int i=1; i<=n; i++) f *= i; return f; } int comb(int n, int r) { return fact(n)/(fact(r)*fact(n-r)); } void PrintKhayam(int n) { for(int p=0; p<=n; p++) { for(int r=0; r<=p; r++) cout << setw(3) << comb(p, r); cout << endl; } } void main() { PrintKhayam( 8 ); }
#include <iostream.h> /* void main() { int a = 0; int d1 = 0; while( a != -1000 ) { if( d1 != 0 ) cout << a << endl; cin >> a; d1++; } } //*/ /* void main() { int a = 0; int d1 = 0; while( d1 < 5 ) { cin >> a; cout << a << endl; d1++; } } //*/ /* void main() { int d1 = 1; while( d1 <= 15 ) { cout << d1 << endl; d1++; } } //*/ /* void main() { int n; cin >> n; int i = 1; while( i <= n ) { cout << i << endl; i++; } } //*/ /* void main() { int n; cin >> n; int s = 0; int i = 1; while( i <= n ) { s = s + i; i++; } cout << s << endl; } //*/ /* void main() { int n; cin >> n; int s = 1; int i = 1; while( i <= n ) { s *= i; i++; } cout << s << endl; } //*/ /* void main() { for(int i=1; i<=15; i++) { cout << i << endl; } } //*/ /* void main() { int i=1; for( ; ; ) { if( i > 15 ) break; cout << i << endl; i++; } } //*/ /* void main() { for(int i=2; i<=20; i += 2) { cout << i << endl; } } //*/ void main() { double a, b; int n; cin >> a >> b >> n; for(double x=a; x<=b; x += (b-a)/n ) cout << x << endl; }
#include <iostream.h> #include <conio.h> //CodeBlocks /* void main() { double x; cout << "Enter X>"; cin >> x; double y = x*x-1; cout << "f(" << x << ")=" << y << endl; getch(); } //*/ /* void main() { double x; cout << "Enter X>"; cin >> x; double y;// = x*x-1; if( x > 0 ) y = x*x-1; else y = -1+x; cout << "f(" << x << ")=" << y << endl; getch(); } //*/ //void main() { /* if( -2 ) cout << 2 << endl; else cout << 3 << endl; //*/ /* int x = 2; if( x-2 ) cout << 2 << endl; else cout << 3 << endl; //*/ //cout << (2>3) << endl; /* int x = 2; if( x == 3 ) cout << 2 << endl; else cout << 3 << endl; } //*/ /* void main() { char ch; cout << "Enter a Char>"; cin >> ch; if( ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' ) cout << "Alphabetical" << endl; else cout << "non-Alphabetical" << endl; } //*/ /* void main() { cout << "Enter Mark>"; double mark; cin >> mark; if( mark < 10 ) { cout << "Sorry!" << endl; cout << 9 << endl; } else { if( mark < 19 ) { cout << mark+1 << endl; cout << "Afarin" << endl; } else { if( mark <= 20 ) { cout << 20 << endl; cout << "100 Afarin" << endl; } else { cout << "Error!" << endl; } } } } //*/ void main() { cout << "Enter Mark>"; double mark; cin >> mark; if( mark < 0 ) cout << "Error" << endl; else if( mark < 10 ) cout << 9 << endl; else if( mark < 19 ) cout << mark+1 << endl; else if( mark <= 20 ) cout << 20 << endl; else cout << "Error!" << endl; }
#include <iostream.h> #include <math.h> /* //Prog 1. void main() { int a; cout << "Enter a number>"; cin >> a; cout << "You typed " << a << endl; } //*/ /* //Prog 2. void main() { //1. Input cout << "Enter X>"; double x; cin >> x; //2. Process double y = x*x-1; //3. Output cout << "f(" << x << ")=" << y << endl; } //*/ /* //Prog 3. void main() { //I int n; cout << "Enter N>"; cin >> n; //P int d0 = n % 10; int d1 = (n / 10)%10; //O cout << "Yekan = " << d0 << endl; cout << "Dahegan = " << d1 << endl; } ///*/ /* //Prog 4. void main() { //I int n; cout << "Enter N>"; cin >> n; //P int d0 = n % 10; int d1 = (n / 10)%10; int d2 = (n / 100)%10; //O cout << "Yekan = " << d0 << endl; cout << "Dahegan = " << d1 << endl; cout << "Sadegan = " << d2 << endl; } //*/ /* //Prog 5. void main() { //I int n; cout << "Enter N>"; cin >> n; //P int d0 = n % 10; int d1 = (n / 10)%10; n = n/100; n = 10*n+d0; n = 10*n+d1; cout << n << endl; } //*/ /* //Prog 6. void main() { int n; cout << "Enter N>"; cin >> n; int l = int(log10(n))+1; cout << l << endl; } //*/ //Prog 7. void main() { int n; cout << "Enter N>"; cin >> n; int l = int(log10(n))+1; int p = int( pow(10, l-1) ); cout << n/p << endl; }
- امتحان میان ترم:
- 1389/02/14 - 15:30
- امتحان پایان ترم:
- 1389/03/31 - 08:30