Unresolved external symbol calling funtion same .cpp - unresolved-external

I am trying to make a program to find saddle points in a matrix. When i try to run it compiler shows errors: [Linker error] undefined reference to min_cols(float (*) [6], float, int, int, int)' , [Linker error] undefined reference tomax_rows(float (*) [6], float, int, int, int)'
That is my code
#include <stdio.h>
#define M 8
#define N 6
void main (){
void enter_matrix (float p[M][N], int r, int c);
void print_matrix (float p[M][N], int r, int c);
void min_cols (float p[M][N],float ,int , int r, int c);
void max_rows (float p[M][N],float mr,int mri, int r, int c);
int saddle_points (float max_row[N],int mrow_i[N],float min_col[N],int mcol_i[N],int r,int c);
int m, n,mrow_i[M],mcol_i[N],flag;
int *mri,*mci;
float matrix[M][N],max_row[M],min_col[N];
float (*p) [M][N],*mr,*mc;
p=&matrix;mr=max_row;mc=min_col;
mri=mrow_i;mci=mcol_i;
do{
printf("Please enter matrix size(max 8 by 6):'\n ");
printf("Enter number of rows M=");
scanf("%d",&m);
printf("Enter number of columns N=");
scanf("%d",&n);
}
while((m>M||m<=0)||(n>N||n<=0));
enter_matrix(*p,m,n);
print_matrix(*p,m,n);
min_cols(*p,min_col[N],mcol_i[N],m,n);
max_rows(*p,max_row[M],mrow_i[M],m,n);
printf("Saddle points:\n");
flag=saddle_points (max_row,mrow_i,min_col,mcol_i,m,n);
if(flag==0){
printf("There are no saddle points");
}
}
void enter_matrix (float p[M][N], int r, int c){
int i,j;
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf("Enter %d %d element of matrix: ",i+1,j+1);
scanf("%f",&p[i][j]);
}
}
}
void print_matrix (float p[M][N], int r, int c){
int i,j;
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf("%f \t",p[i][j]);
}
printf("\n");
}
}
void min_cols (float p[M][N],float min_col[N],int mcol_i[N],int r, int c){
int i,j,*mci;float min,*mc;
mc=min_col;mci=mcol_i;
for(i=0;i<r;i++){
min=p[i][0];
for(j=0;j<c;j++){
if(p[i][j]<min){
*(mc+i)=p[i][j];
*(mci+i)=j;
}
}
}
}
void max_rows (float p[M][N],float max_row[M],int mrow_i[M], int r, int c){
int i,j,*mri;float max,*mr;
mr=max_row;mri=mrow_i;
for(j=0;j<c;j++){
max=0;
for(i=0;i<r;i++){
if(p[i][j]>max){
*(mr+j)=p[i][j];
*(mri+j)=j;
}
}
}
}
int saddle_points (float max_row[N],int mrow_i[N],float min_col[N],int mcol_i[N],int r,int c){
int i,j,flag=0,*mri,*mci; float *mr,*mc;
mr=max_row;mri=mrow_i;mc=min_col;mci=mcol_i;
for(i=0;i<r;i++){
for(j=0;j<c;j++){
if(*(mr+i)==*(mc+j)){
printf("Saddle point at row %d, col %d value:%f'n",*(mri+i),*(mci+i),*(mr+i));
flag=1;
}
}
return flag;
}
}

Found the solution i should have put the prototypes of functions before main this is the working code:
#include <stdio.h>
#define M 8
#define N 6
void enter_matrix (float p[M][N], int r, int c);
void print_matrix (float p[M][N], int r, int c);
void min_cols (float p[M][N],float min_col[N],int mcol_i[N],int r, int c){
int i,j,*mci;float min,*mc;
mc=min_col;mci=mcol_i;
for(i=0;i<r;i++){
min=p[i][0];
for(j=0;j<c;j++){
if(p[i][j]<min){
*(mc+i)=p[i][j];
*(mci+i)=j;
}
}
}
}
void max_rows (float p[M][N],float max_row[M],int mrow_i[M], int r, int c){
int i,j,*mri;float max,*mr;
mr=max_row;mri=mrow_i;
for(j=0;j<c;j++){
max=0;
for(i=0;i<r;i++){
if(p[i][j]>max){
*(mr+j)=p[i][j];
*(mri+j)=j;
}
}
}
}
int saddle_points (float max_row[N],int mrow_i[N],float min_col[N],int mcol_i[N],int r,int c);
void main (){
int m, n,mrow_i[M],mcol_i[N],flag;
int *mri,*mci;
float matrix[M][N],max_row[M],min_col[N];
float (*p) [M][N],*mr,*mc;
p=&matrix;mr=max_row;mc=min_col;
mri=mrow_i;mci=mcol_i;
do{
printf("Please enter matrix size(max 8 by 6):'\n ");
printf("Enter number of rows M=");
scanf("%d",&m);
printf("Enter number of columns N=");
scanf("%d",&n);
}
while((m>M||m<=0)||(n>N||n<=0));
enter_matrix(*p,m,n);
print_matrix(*p,m,n);
min_cols(*p,min_col,mcol_i,m,n);
max_rows(*p,max_row,mrow_i,m,n);
printf("Saddle points:\n");
flag=saddle_points (max_row,mrow_i,min_col,mcol_i,m,n);
if(flag==0){
printf("There are no saddle points");
}
}
void enter_matrix (float p[M][N], int r, int c){
int i,j;
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf("Enter %d %d element of matrix: ",i+1,j+1);
scanf("%f",&p[i][j]);
}
}
}
void print_matrix (float p[M][N], int r, int c){
int i,j;
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf("%f \t",p[i][j]);
}
printf("\n");
}
}
int saddle_points (float max_row[N],int mrow_i[N],float min_col[N],int mcol_i[N],int r,int c){
int i,j,flag=0,*mri,*mci; float *mr,*mc;
mr=max_row;mri=mrow_i;mc=min_col;mci=mcol_i;
for(i=0;i<r;i++){
for(j=0;j<c;j++){
if(*(mr+i)==*(mc+j)){
printf("Saddle point at row %d, col %d value:%f'n",*(mri+i),*(mci+i),*(mr+i));
flag=1;
}
}
return flag;
}
}

Related

Sort an array A using Quick Sort. Using reccursion

#include<iostream>
using namespace std;
void quickSort(int input[], int start, int end)
{
// your code goes here
}
void quickSort(int input[], int size)
{
quickSort(input, 0, size - 1);
}
*/
void swap(int* a,int* b){
int temp=*a;
*a=*b;
*b=temp;
}
int count(int input[],int start,int end ){
static int c=0;
if(start==end)
return c;
if(input[start]>input[end])
c++;
return count(input,start,end-1);
}
int partionArray(int input[],int start,int end ){
int c=count(input,start,end);
int pi=c+start;
swap(&input[start],&input[pi]);
int i=start;
int j=end;
while(i<pi&&j>pi)
{
if(input[i]<input[pi])
{
i++;
}
else if(input[j]>=input[pi])
{
j--;
}
else
{
swap(&input[i],&input[j]);
i++;
j--;
}
}
return pi;
}
void qs(int input[],int start, int end){
if(start>=end)
return;
int pi=partionArray(input,start,end);
qs(input,start,pi-1);
qs(input,pi+1,end);
}
void quickSort(int input[], int size) {
qs(input,0,size-1);
}
int main(){
int n;
cin >> n;
int *input = new int[n];
for(int i = 0; i < n; i++) {
cin >> input[i];
}
quickSort(input, n);
for(int i = 0; i < n; i++) {
cout << input[i] << " ";
}
delete [] input;
}
Sort an array A using Quick Sort. Using reccursion is the question.
Input format :
Line 1 : Integer n i.e. Array size
Line 2 : Array elements (separated by space)
Output format :
Array elements in increasing order (separated by space)
Constraints :
1 <= n <= 10^3
What did i do wrong in this code pls can any one explain?Is every thing right with this code?

Backtrack the difference between these two codes

I have been trying to play around with backtracking. From my understanding these two codes are doing same thing but somehow I got different outcomes.
I am just trying to use some type of template to start with.
cout<<i<<endl;
backtrack(i+1);
backtrack(i+1);
and
for(int i=start; i<n; i++){
cout<<i<<endl;
backtrack(i+1);
}
The first one gets 5 as outcome and the second one gets six when I have the input of
nums=[1,1,1,1,1]
target = 3
public class Solution {
int count = 0;
public int findTargetSumWays(int[] nums, int S) {
calculate(nums, 0, 0, S);
return count;
}
public void calculate(int[] nums, int i, int sum, int S) {
if (i == nums.length) {
if (sum == S) {
count++;
}
} else {
calculate(nums, i + 1, sum + nums[i], S);
calculate(nums, i + 1, sum - nums[i], S);
}
}
}
class Solution {
public:
int count;
void backtrack(vector<int>& nums, int target, int start, int sum){
if(start==nums.size()){
if(sum==target){
count++;
}
return;
}
else{
for(int i=start; i<nums.size(); i++){
//sum+=nums[i];
backtrack(nums, target, i+1, sum+nums[i]);
sum-=nums[i];
}
}
}
int findTargetSumWays(vector<int>& nums, int target) {
count=0;
int sum=0;
int total=0;
for(auto x:nums)total+=x;
vector<vector<int>> dp;
backtrack(nums, target, 0, sum);
return count;
}
};

Point class. distance formula. logic issue when plugging coordinate from the constructor and getting wrong result

#include <iostream>
#include <cmath>
using namespace std;
class point{ // define point class
private:
float x=0;
float y=0;
public:
point();// default constructor
point(float, float);// constructor
void setX(float);
void setY(float);
double getX()const;
double getY()const;
};
//implement all the member function
point::point(){ }
point::point(float i, float k){
x=i;
y=k;
}
void point::setX(float xc){
x=xc;
}
void point::setY(float yc){
y=yc;
}
double point::getY()const{
return y;
}
double point::getX()const{
return x;
}
double operator + (const point&lhs, const point &rhs) // free function.
{
double dx=lhs.getX()-rhs.getX();
double dy=lhs.getX()-rhs.getY();
return sqrt(dx*dx+dy*dy);
}
int main(){
point p1(2, -1);
point p2(1, 5);
int dist=0;
dist = p1 + p2;
cout << "The distance between p1 " << "and p2" << " is " << dist << endl;
return 0;
}
This should be 5 but I got 3. I do not understand why?
replace
double dy=lhs.getX()-rhs.getY();
by
double dy=lhs.getY()-rhs.getY()

RSA algorithm in the SSL

I want to know about the explanation of RSA, here is the example
Select primes: p=17 & q=11
Compute n = pq =17×11=187
Compute ø(n)=(p–1)(q-1)=16×10=160
Select e : gcd(e,160)=1; choose e=7
Determine d: de=1 mod 160 and d < 160 Value is d=23 since 23×7=161= 10×160+1
Publish public key KU={7,187}
Keep secret private key KR={23,17,11}
Look at the prime numbers written above, how can i know from where those prime numbers are generated.
Those prime numbers can be generated randomly by the RSA algorithm. In this example they are very small, but in real life the would be very very large. The algorithm will also take some other precautions when generating the primes. For instance, p and q should not be close to one another.
here is the code that implements RSA
try out this code
/*Arpana*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long int p,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i;
char msg[100];
int prime(long int);
void ce();
long int cd(long int);
void encrypt();
void decrypt();
void main()
{
clrscr();
printf("\nENTER FIRST PRIME NUMBER\n");
scanf("%d",&p);
flag=prime(p);
if(flag==0)
{
printf("\nWRONG INPUT\n");
getch();
exit(1);
}
printf("\nENTER ANOTHER PRIME NUMBER\n");
scanf("%d",&q);
flag=prime(q);
if(flag==0||p==q)
{
printf("\nWRONG INPUT\n");
getch();
exit(1);
}
printf("\nENTER MESSAGE\n");
fflush(stdin);
scanf("%s",msg);
for(i=0;msg[i]!=NULL;i++)
m[i]=msg[i];
n=p*q;
t=(p-1)*(q-1);
ce();
printf("\nPOSSIBLE VALUES OF e AND d ARE\n");
for(i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
getch();
}
int prime(long int pr)
{
int i;
j=sqrt(pr);
for(i=2;i<=j;i++)
{
if(pr%i==0)
return 0;
}
return 1;
}
void ce()
{
int k;
k=0;
for(i=2;i<t;i++)
{
if(t%i==0)
continue;
flag=prime(i);
if(flag==1&&i!=p&&i!=q)
{
e[k]=i;
flag=cd(e[k]);
if(flag>0)
{
d[k]=flag;
k++;
}
if(k==99)
break;
}
}
}
long int cd(long int x)
{
long int k=1;
while(1)
{
k=k+t;
if(k%x==0)
return(k/x);
}
}
void encrypt()
{
long int pt,ct,key=e[0],k,len;
i=0;
len=strlen(msg);
while(i!=len)
{
pt=m[i];
pt=pt-96;
k=1;
for(j=0;j<key;j++)
{
k=k*pt;
k=k%n;
}
temp[i]=k;
ct=k+96;
en[i]=ct;
i++;
}
en[i]=-1;
printf("\nTHE ENCRYPTED MESSAGE IS\n");
for(i=0;en[i]!=-1;i++)
printf("%c",en[i]);
}
void decrypt()
{
long int pt,ct,key=d[0],k;
i=0;
while(en[i]!=-1)
{
ct=temp[i];
k=1;
for(j=0;j<key;j++)
{
k=k*ct;
k=k%n;
}
pt=k+96;
m[i]=pt;
i++;
}
m[i]=-1;
printf("\nTHE DECRYPTED MESSAGE IS\n");
for(i=0;m[i]!=-1;i++)
printf("%c",m[i]);
}

Why does this keep giving errors?

I'm trying to code some stuff for a game but I keep getting error messages on 8 lines that keep saying "Expected '=', ',', ';', 'asm' or 'attribute' before "insert what it's talking about here""
Its annoying and I can't figure out why. Here is the code:
class Vec2 **"error here before Vec2"**
{
public:
float X, Y;
Vec2() {}
Vec2(const float &x, const float &y) :
X(x),
Y(y)
{
};
float &operator[] (const int &index)
{
switch (index)
{
case 0:
return X;
case 1:
return Y;
}
throw Exceptions::IndexOutOfRange();
};
float *operator & ()
{
return &X;
};
};
template<> class TypeInfo<Vec2> : public TypeInfo_Atomic<Vec2> {}; **"error here before <"**
class Vec3 **"error here before Vec3"**
{
public:
float X, Y, Z;
Vec3() {}
Vec3(const float &x, const float &y, const float &z) :
X(x),
Y(y),
Z(z)
{
};
float &operator[] (const int &index)
{
switch (index)
{
case 0:
return X;
case 1:
return Y;
case 2:
return Z;
}
throw Exceptions::IndexOutOfRange();
};
float *operator & ()
{
return &X;
};
};
template<> class TypeInfo<Vec3> : public TypeInfo_Atomic<Vec3> {}; **"error here before <"**
class Vec4 **"error here before Vec4"**
{
public:
float X, Y, Z, W;
Vec4() {}
Vec4(const float &x, const float &y, const float &z, const float &w) :
X(x),
Y(y),
Z(z),
W(w)
{
};
float &operator[] (const int &index)
{
switch (index)
{
case 0:
return X;
case 1:
return Y;
case 2:
return Z;
case 3:
return W;
}
throw Exceptions::IndexOutOfRange();
};
float *operator & ()
{
return &X;
};
};
template<> class TypeInfo<Vec4> : public TypeInfo_Atomic<Vec4> {}; **"error here before <"**
class Color **"error here before Color"**
{
public:
byte R, G, B, A;
Color() {}
Color(byte r, byte g, byte b, byte a) :
R(r),
G(g),
B(b),
A(a)
{
};
byte *operator & ()
{
return &R;
};
static const Color Red,
Green,
Blue,
Yellow,
White,
Black;
};
template<> class TypeInfo<Color> : public TypeInfo_Atomic<Color> {}; **"flag here before <"**
there are 8 errors total. Help would be hugely appreciated!
If you're putting objective-c and c++ code into the same file, you need to use a .mm file extension.
http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html
It doesn't think your module is C++. What suffix did you give the file?