19-10-2010, 06:22 AM
|
#4
|
تاريخ التسجيل: Jul 2008
كلية: كلية الحاسبات وتقنية المعلومات
التخصص: IT
نوع الدراسة: عضو هيئة تدريس
المستوى: متخرج
البلد: جــــدة
الجنس: ذكر
المشاركات: 2,477
|
رد: كيف اشغل ملف بلغة ال c++
نعم ,, للاسف , بعض بيئات التطوير لا تلتزم بالشكل القياسي لكتابة اللغة , فتجد مثلاً الكود السابق ربما يشتغل على dev C++ بدون مشاكل أو برنامج آخر ...
عموماً ,,, تعديل الكود ليعمل على الفجوال ستديو :
كود PHP:
//-------------------------------------------------------------------------------
#include <iostream>
#include <conio.h>
#include <time.h>
#include <vector>
using namespace std;
double diffclock(clock_t clock1,clock_t clock2);
//--------------------------------------------------------------------------------
int main()
{
//clrscr();
system("CLS") ;
//--------------------------------------------------------------------------------
int size = 0; //size of the matrix.
int BlockSize = 0;
clock_t end,begin;
int m;
char a;
//--------------------------------------------------------------------------------
//Compiler directive to increase the buffer and memory size
std::vector<std::vector<int> > A(1000, std::vector<int>(1000));
std::vector<std::vector<int> > B(1000, std::vector<int>(1000));
std::vector<std::vector<int> > C(1000, std::vector<int>(1000));
//--------------------------------------------------------------------------------
//ask the user about multiplication method.
do{
//clrscr();
system("CLS") ;
cout << "\n\t ------------------------------------------------------";
cout << "\n\t ````````````````` Welcome `````````````````` ";
cout << "\n\t `````` Matrix Multiplication Program `````` ";
cout << "\n\t ------------------------------------------------------";
cout << "\n Enter the size of the Matrix : ";
cin >> size;
cout << "\n\n Choose the Matrix Multiplication Method:\n";
cout << " 1. Row by Column.\n";
cout << " 2. Row by Row.\n";
cout << " 3. Column by Column.\n";
cout << " 4. Block Matrix (Row by Column).\n";
cout << " 5. Block Matrix (Row by Row).\n";
cout << " 6. Block Matrix (Column by Column).\n\n";
cout << " ";
cin >> m;
//-------------------------------------------------------------------------------
//initilize the matrix.
for(int i = 0 ; i < size ; i++)
{
for(int j = 0 ; j < size ; j++)
{
A[i][j]= 1;
B[i][j]=1;
C[i][j]=0;
}
}
//--------------------------------------------------------------------------------
if(m == 1){
//Multiply the matrix B by matrix C Row by column (regular).
begin = clock();
for(int i = 0 ; i < size ; i++)
for(int j = 0 ; j < size ; j++)
for(int k = 0 ;k < size ; k++)
A[i][j] += B[i][k]* C[k][j];
end = clock();
//--------------------------------------------------------------------------------
//display the result.
cout << "\n\n The (Row by column) Multiplication result :\n\n";
cout<<"\n\n The Execution Time: "<<diffclock(end,begin)<<" ms."<<endl;
}
//--------------------------------------------------------------------------------
else if(m == 2){
//Multiply the matrix B by matrix C Row by Row.
begin = clock();
for(int i = 0 ; i < size ; i++)
for(int j = 0 ; j < size ; j++)
for(int k = 0 ;k < size ; k++)
A[i][k] += B[i][j]* C[j][k];
end = clock();
//--------------------------------------------------------------------------------
//display the result.
cout << "\n\n The (Row by Row) Multiplication result :\n\n";
cout<<"\n\n The Execution Time: "<<diffclock(end,begin)<<" ms."<<endl;
}
//--------------------------------------------------------------------------------
else if(m == 3){
//Multiply the matrix B by matrix C column by column.
begin = clock();
for(int i = 0 ; i < size ; i++)
for(int j = 0 ; j < size ; j++)
for(int k = 0 ;k < size ; k++)
A[k][i] += B[k][j]* C[j][i];
end = clock();
//--------------------------------------------------------------------------------
//display the result.
cout << "\n\n The (column by column) Multiplication result :\n\n";
cout<<"\n\n The Execution Time: "<<diffclock(end,begin)<<" ms."<<endl;
}
//--------------------------------------------------------------------------------
else if(m == 4){
//Multiply the Block matrix B by Block matrix C Row by Column.
cout<< "\n Enter the Block Size : ";
cin>> BlockSize;
while(BlockSize > size)
{cout <<"\n You must enter the block size less than the size!";
cout<< "\n Enter the Block Size : ";
cin>>BlockSize;
}
while(size % BlockSize != 0)
{cout <<"\n You must enter the block size divisible by the size!";
cout<< "\n Enter the Block Size : ";
cin>>BlockSize;
}
begin = clock();
for (int i1 = 0; i1 < size ; i1+=BlockSize)
for (int j1 = 0; j1 < size ; j1 += BlockSize)
for (int k1 = 0; k1 < size ; k1 += BlockSize)
for (int i = i1; i < i1 + BlockSize && i < size ; i++)
for (int j = j1; j <j1 + BlockSize && j<size; j++)
for (int k = k1; k < k1 + BlockSize && k < size; k++)
A[i][j] += B[i][k]* C[k][j];
end = clock();
//--------------------------------------------------------------------------------
//display the result.
cout << "\n\n The Block Matrix(Row by Column) Multiplication result :\n\n";
cout<<"\n\n The Execution Time: "<<diffclock(end,begin)<<" ms."<<endl;
}
//--------------------------------------------------------------------------------
else if(m == 5){
//Multiply the Block matrix B by Block matrix C Row by Row.
cout<< "\n Enter the Block Size : ";
cin>> BlockSize;
while(BlockSize > size)
{cout <<"\n You must enter the block size less than the size!";
cout<< "\n Enter the Block Size : ";
cin>>BlockSize;
}
while(size % BlockSize != 0)
{cout <<"\n You must enter the block size divisible by the size!";
cout<< "\n Enter the Block Size : ";
cin>>BlockSize;
}
begin = clock();
for (int i1 = 0; i1 < size ; i1+=BlockSize)
for (int j1 = 0; j1 < size ; j1 += BlockSize)
for (int k1 = 0; k1 < size ; k1 += BlockSize)
for (int i = i1; i < i1 + BlockSize && i < size ; i++)
for (int j = j1; j <j1 + BlockSize && j<size; j++)
for (int k = k1; k < k1 + BlockSize && k < size; k++)
A[i][k] += B[i][j]* C[j][k];
end = clock();
//--------------------------------------------------------------------------------
//display the result.
cout << "\n\n The Block Matrix(Row by Row) Multiplication result :\n\n";
cout<<"\n\n The Execution Time: "<<diffclock(end,begin)<<" ms."<<endl;
}
//--------------------------------------------------------------------------------
else if(m == 6){
//Multiply the Block matrix B by Block matrix C Col by Col.
cout<< "\n Enter the Block Size : ";
cin>> BlockSize;
while(BlockSize > size)
{cout <<"\n You must enter the block size less than the size!";
cout<< "\n Enter the Block Size : ";
cin>>BlockSize;
}
while(size % BlockSize != 0)
{cout <<"\n You must enter the block size divisible by the size!";
cout<< "\n Enter the Block Size : ";
cin>>BlockSize;
}
begin = clock();
for (int i1 = 0; i1 < size ; i1+=BlockSize)
for (int j1 = 0; j1 < size ; j1 += BlockSize)
for (int k1 = 0; k1 < size ; k1 += BlockSize)
for (int i = i1; i < i1 + BlockSize && i < size ; i++)
for (int j = j1; j <j1 + BlockSize && j<size; j++)
for (int k = k1; k < k1 + BlockSize && k < size; k++)
A[k][i] += B[k][j]* C[j][i];
end = clock();
//--------------------------------------------------------------------------------
//display the result.
cout << "\n\n The Block Matrix(Column by Column) Multiplication result :\n\n";
cout<<"\n\n The Execution Time: "<<diffclock(end,begin)<<" ms."<<endl;
}
//--------------------------------------------------------------------------------
else {
cout << "\n Select the number from the list";
}
//--------------------------------------------------------------------------------
cout << "\n\n Do you want to try again (y/n): ";
cin >> a;
if(a == 'n')
return 0;
}while(a == 'y');
} //end main.
//--------------------------------------------------------------------------------
double diffclock(clock_t clock1,clock_t clock2)
{
double diffticks=clock1-clock2;
double diffms=(diffticks)/(CLOCKS_PER_SEC/1000);
return diffms;
}
|
|
سبحان الله وبحمد ,,, سبحان الله العظيم الحمد لله كما ينبغي لجلال وجهه وعظيم سلطانه . اللهم صل على محمد وعلى آل محمد كما صليت على إبراهيم وعلى آل إبراهيم إنك حميد مجيد . اللهم بارك على محمد وعلى آل محمد كما باركت على إبراهيم وعلى آل إبراهيم إنك حميد مجيد.
|
|
|
|