#include<iostream>
#include<conio.h>
#include<string>
typedef string stringer
void main(){
stringer mailto = "yilmazburk@gmail.com";
cout << mailto << endl;
}
Thursday, 15 March 2012
string library
Tuesday, 13 March 2012
Problem Getline is solved
Getline function sometimes runs badly i mean it's work useless for us so i can help you about getline's useless
/*****************************************************************************
using getline function/getline fonksiyonun istenildiği gibi kullanılması
******************************************************************************/
#include<string>
#include<iostream>
using namespace std;
void main(){
string film_name,country;
bool oscar;
int duration,number_of_actors;
double imdb_rating;
string getliner;
cout << "Please enter film's name : " << "\n";
cin.ignore(0,'\n'); //not read space and nextline character
getline(cin,film_name);
cout << "Please enter film's year : "<< endl;
cin >> year;
cout << "Please enter film's duration : "<< endl;
cin >> duration;
cout << "Please enter number of actors : "<< endl;
cin >> number_of_actors;
getline(cin,getliner);
cout << "Please enter film's country : "<< "\n";
cin.ignore(0,'\n'); //not read space and nextline character
getline(cin,country);
cout << "Does the film have Oscar 0 or 1 : "<< endl;
cin >> oscar;
cout << "Please enter imdb rating of the film : "<< endl;
cin >> imdb_rating;
getline(cin,getliner);
cout << "Film added" << endl;
cin.clear();
}
Saturday, 3 March 2012
Memory Allocation in cpp with 2 Dimensional Arrays
Operation on matrices with pointers/Pointerlar ve Diziler Üzerinde hafıza işlemleri
/***********************************************************
Memory Allocation and Matrices Operations with pointers
************************************************************/
#include <iostream>
#include <ctimegt>
#include <cstdlibgt>
using namespace std;
/**********************************************************************************
*FONKSİYONUN ADI: multip_matrix
*ALDIĞI PARAMETRELER: int** ve int
*DÖNÜŞ DEĞERİ: void
*AMACI: İki boyutlu 2 diziyi matris ve işaretçi aritmetiğine göre çarpan fonksiyon
**********************************************************************************/
void multip_matrix(int **a, int **b, int **c, int k, int m, int n){
int i,j,l;
int sum=0;
for(l=0;l<n;l++)
for(i=0;i<k;i++){
for(j=0;j<m;j++){
sum+=*(*(b+j)+l)**(*(a+i)+j);
}
*(*(c+i)+l) = sum;
sum = 0;
}
}
/**********************************************************************************
*FONKSİYONUN ADI: multip_array
*ALDIĞI PARAMETRELER: int* ve int
*DÖNÜŞ DEĞERİ: void
*AMACI: Tek boyutlu 2 diziyi matris ve işaretçi aritmetiğine göre çarpan fonksiyon
**********************************************************************************/
void multip_array(int *a, int *b, int *c, int k, int m, int n){
int i,j,l;
int sum = 0;
for(l=0;l<n;l++)
for(i=0;i<k;i++){
for(j=0;j<m;j++)
sum += *(a+j+i*k)**(b+j*n+l);
*(c+i*n+l) = sum;
sum = 0;
}
}
int main(){
srand(time(NULL));
int k,m,n;
int x = 0;
int i,j,z,l;
int sayac = 0;
cout << "Matrislerin Boyutlarini Girin (k,m,n seklinde)" <<endl;
cin >> k >> m >> n;
//a dizisi için hafızadan yer alınıyor ve dizi oluşturuluyor
int **a;
a = new int*[k];
for(i=0;i<k;i++)
a[i] = new int[m];
for(j=0;j<k;j++)
for(z=0;z<m;z++)
a[j][z] = rand()%6;
//a dizisinin elemanlar ekrana bastırılıyor
cout << "1.matris"<<endl;
for(i=0;i<k;i++)
for(j=0;j<m;j++){
cout << a[i][j]<<" ";
sayac++;
if(sayac == m){
cout<<endl;
sayac = 0;
}
}
cout << endl;
//b dizisi için hafızadan yer alınıyor ve dizi oluşturuluyor
int **b ;
b = new int*[m];
for(i=0;i<m;i++)
b[i] = new int[n];
for(j=0;j<m;j++)
for(z=0;z<n;z++)
b[j][z] = rand()%6;
//b dizisinin elemanlar ekrana bastırılıyor
cout << "2.matris"<<endl;
for(i=0;i<m;i++)
for(j=0;j<n;j++){
cout << b[i][j]<<" ";
sayac++;
if(sayac == n){
cout<<endl;
sayac = 0;
}
}
cout << endl;
//c dizisi için hafızadan yer alınıyor ve dizi oluşturuluyor
int **c = new int*[k];
for(i=0;i<k;i++)
c[i] = new int[n];
system("pause");
//multip_matrix fonksiyon çağrısı
multip_matrix(a,b,c,k,m,n);
//multip matrix fonksiyonu ile oluşturulan iki boyutlu çarpım dizisinin ekrana bastırılması
cout << "carpim matrisi"<<endl;
for(i=0;i<k;i++)
for(j=0;j<n;j++){
printf("%2d ",c[i][j]);
sayac++;
if(sayac == n){
cout<<endl;
sayac = 0;
}
}
//tek boyutlu diziler icin hafızadan yer alınıyor
int *dizi1 = new int[k*m];
int *dizi2 = new int[m*n];
int *dizi3 = new int[k*n];
for(i=0;i<k;i++)
for(j=0;j<m;j++){
dizi1[x] = a[i][j];
x++;
}
x=0;
for(i=0;i<m;i++)
for(j=0;j<n;j++){
dizi2[x] = b[i][j];
x++;
}
cout<<endl;
system("pause");
//multip_array fonksiyon çağrısı
multip_array(dizi1,dizi2,dizi3,k,m,n);
//multip array fonksiyonu ile oluşturulan tek boyutlu çarpım dizisinin ekrana bastırılması
for(i=0;i<k*n;i++)
cout<< *(dizi3+i) <<" ";
cout<<endl;
//Her bir dizi için bellekten alınan yerler geri veriliyor
for(i=0;i<k*m;i++)
delete a[i];//Try This
delete [] a;
for(i=0;i<m*n;i++)
delete b[i];//Try This
delete [] b;
delete [] dizi1;
delete [] dizi2;
delete [] dizi3;
system("pause");
return 0;
}
Ekran çıktısı aşağıdaki gibidir
Etiketler:
2 Dimensional,
Allocation,
Array,
Arrays,
Matrix,
Memory,
Pointer
Subscribe to:
Comments (Atom)
