|
Here is the definition USN_RECORD_COMMON_HEADER
typedef struct {
DWORD RecordLength;
WORD MajorVersion;
WORD MinorVersion;
} USN_RECORD_COMMON_HEADER, *PUSN_RECORD_COMMON_HEADER;
|
|
|
|
|
Have a look in Winioctl.h to check the definitions of these types. My version compiles them fine on VS2017 and Windows 10.
|
|
|
|
|
Check the typedef s of the three structures that fail for mutual non standard members.
A candidate is the USN member.
Do you have a define directive using the same name anywhere in your project?
If that does not help enable the creation of preprocessor output files. Then you can check what the compiler "sees".
|
|
|
|
|
|
i was going through a article about friend function and then in i came across this code:
#include <iostream>
using namespace std;
class Distance
{
private:
int meter;
public:
Distance(): meter(0) { }
friend int addFive(Distance);
};
int addFive(Distance d)
{
d.meter += 5;
return d.meter;
}
int main()
{
Distance D;
cout<<"Distance: "<< addFive(D);
return 0;
}
in the above code what is
Quote: Distance(): meter(0) { }
and how is a object of class distance is able to access a private member ?Quote: int addFive(Distance d)
{
//accessing private data from non-member function
d.meter += 5;
return d.meter;
}
Thank you.
|
|
|
|
|
|
You should get hold of a good C++ book. Probably the best would be the one written by Bjarne Stroustrup[^]
|
|
|
|
|
Welcome to C++ .
I mean:
- constructors are the very basics of an OOP language (you must be sure to grasp them before even attempting to code).
- accessing an otherwise unaccessible member is the very purpose of the
friend declaration.
|
|
|
|
|
Problem statement: You are given Q queries. Each query consists of a single number N. You can perform any of the 2 operations on in each move:
1: If we take 2 integers a and b where N=aXb(a!=1,b!=1) then we can change N=max(a,b).
2: Decrease the value of N by 1. Determine the minimum number of moves required to reduce the value of N to 0
Input Format
The first line contains the integer Q.
The next Q lines each contain an integer,N .
Output Format
Output Q lines. Each line containing the minimum number of moves required to reduce the value of N to 0.
Sample Input
2
3
4
Sample Output
3
3
Explanation
For test case 1, We only have one option that gives the minimum number of moves. Follow 3->2 -> 1->0 .
Hence, 3 moves.
For the case 2, we can either go 4->3 ->2 ->1 ->0 or4 -> 2-> 1->0 . The 2nd option is more optimal. Hence, 3 moves.
My algo:
if a number is N then
I do looping until sqrt(N) to find if it is a prime or not.
if it is a prime number then N=N-1
if it not a prime number,one of the largest factor(say a) is <=sqrt(N) then other will be b=N/a now b>a then put N=b;
increment count(pass by value).
then next iteration for N ,until it is greater than 1.
return count.
algorithms works fine with small value but predicts less optimal solution for large values.why?
|
|
|
|
|
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
i want to make a program that can convert from class a type to class b & vice versa..
i already made a program that does one type of conversion..
#include <iostream>
#include <cmath>
using namespace std;
class Polar;
class Rectangle{
float length, bredth;
public:
Rectangle(){}
Rectangle(float ,float);
int getLength(){return(length);}
int getBredth(){return(bredth);}
void putLength(float x){length = x;}
void putBredth(float y){bredth = y;}
void putData(){cout<<"Length : "<<length<<"\tBreadth : "<<bredth<<endl;}
~Rectangle(){}
};
Rectangle::Rectangle(float x, float y){
length = x;
bredth = y;
}
class Polar{
float angle, rad;
public:
Polar(){}
Polar(float , float);
operator Rectangle(){
Rectangle temp;
float l = rad*cos(angle), b =rad*sin(angle) ;
temp.putLength(l);
temp.putBredth(b);
return(temp);
}
int getAngle(){return(angle);}
int getRadius(){return(rad);}
void putData(){cout<<"Angle : "<<angle<<"\tRadius : "<<rad<<endl;}
~Polar(){}
};
Polar::Polar(float x, float y){
angle = x;
rad = y;
}
int main(){
Rectangle r1(40, 20.23);
Polar p1(120, 25);
r1 = p1;
r1.putData();
return 0;
}
as in the above code i have converted class Polar to class Rectangle, but i also want to have a conversion of class Rectangle to class Polar.
Thank you
|
|
|
|
|
Tarun Jha wrote: as in the above code i have converted class Polar to class Rectangle,
Did you test it?
Does it work?
I ask because I see neither the assignment operator
Rectangle& Rectangle::operator =(const Polar& polar) nor the ctor to create Rectangle instance from the Polar one...
|
|
|
|
|
but i am not using any variables with reference to heap, so i thought it shouldn't be needed for ex:- new, *variable etc.
|
|
|
|
|
#include <iostream>
#include <cmath>
using namespace std;
class Polar;
class Rectangle
{
float length, bredth;
public:
Rectangle(){}
Rectangle(float ,float);
operator Polar();
int getLength(){return(length);}
int getBredth(){return(bredth);}
void putLength(float x){length = x;}
void putBredth(float y){bredth = y;}
void putData(){cout<<"Length : "<<length<<"\tBreadth : "<<bredth<<endl;}
~Rectangle(){}
};
class Polar{
float angle, rad;
public:
Polar(){}
Polar(float , float);
operator Rectangle();
int getAngle(){return(angle);}
int getRadius(){return(rad);}
void putAngle(float a){angle=a;}
void putRadius(float r){rad = r;}
void putData(){cout<<"Angle : "<<angle<<"\tRadius : "<<rad<<endl;}
~Polar(){}
};
Rectangle::Rectangle(float x, float y)
{
length = x;
bredth = y;
}
Rectangle::operator Polar()
{
Polar temp;
float a = atan2(bredth, length), r = sqrt(length*length + bredth*bredth);
temp.putAngle(a);
temp.putRadius(r);
return(temp);
}
Polar::Polar(float x, float y)
{
angle = x;
rad = y;
}
Polar::operator Rectangle()
{
Rectangle temp;
float l = rad*cos(angle), b =rad*sin(angle);
temp.putLength(l);
temp.putBredth(b);
return(temp);
}
int main()
{
float radians = 120 * M_PI / 180;
Polar p1(radians, 25);
p1.putData();
Rectangle r1 = p1;
r1.putData();
Polar p2 = r1;
p2.putData();
return 0;
}
|
|
|
|
|
thank you
|
|
|
|
|
|
here ih the code below i have tried to add two matrix objects and assign it to the third object but it doesn't give expected result and the rather some garbage value.
include <iostream>
using namespace std;
class matrix{
int **p;
int d1, d2;
public:
matrix(int x=20, int y=20);
void get_element();
void put_element();
int checkAdd(matrix &);
matrix operator + (matrix &);
void operator = (matrix );
~matrix(){
for (int i = 0; i < d1; i++)
delete p[i];
delete p;
}
};
matrix temp;
void matrix::operator = (matrix obj){
this->d1 = obj.d1;
this->d2 = obj.d2;
for(int i=0; i<d1; i++)
for(int j=0; j<d2; j++)
this->p[i][j] = obj.p[i][j];
}
matrix matrix::operator+(matrix &obj){
if(checkAdd(obj)==0)
{
for(int i=0; i<obj.d1; i++)
for(int j=0; j<obj.d2; j++)
temp.p[i][j] = this->p[i][j] + obj.p[i][j];
return(temp) ;
}
cout<<"coloumn and rows of both matrix are not equal !"<<endl;
return (*this);
}
matrix ::matrix(int x, int y)
{
d1 = x;
d2 = y;
p = new int *[d1];
for(int i=0; i<d1; i++)
p[i] = new int [d2];
}
int matrix::checkAdd(matrix &obj){
if((this->d1 == obj.d1) && (this->d2 == obj.d2))
return 0;
else return 1;
}
void matrix::get_element(){
for(int i=0; i<d1; i++)
for(int j=0; j<d2; j++){
cout<<"m["<<i<<"]["<<j<<"] = ";
cin>>p[i][j];
}
}
void matrix::put_element(){
cout<<"\n\n";
for(int i=0; i<d1; i++){
for(int j=0; j<d2; j++){
cout<<p[i][j]<<"\t";
}
cout<<endl;
}
}
int main(){
matrix A(3, 2), B(3, 2), C;
cout<<"Enter matrix elements row by row \n\n";
A.get_element();
A.put_element();
B.get_element();
B.put_element();
C = A + B;
cout<<"\n\n";
C.put_element();
return 0;
}
thank you
|
|
|
|
|
What result did you expect and what did you get?
|
|
|
|
|
Quote: So basically i want to add 2 matrix object and assign the result to the third non-initiated matrix object, without changing the values of first 2 original matrix.
this is the result i am getting.
Quote: Enter matrix elements row by row
m[0][0] = 1
m[0][1] = 2
m[1][0] = 3
m[1][1] = 4
m[2][0] = 5
m[2][1] = 6
1 2
3 4
5 6
m[0][0] = 7
m[0][1] = 8
m[1][0] = 9
m[1][1] = 10
m[2][0] = 11
m[2][1] = 12
7 8
9 10
11 12
8 10 47120720 0 0 0 0 0 0 0 50331651 41272 47127056 0 47120720 0 0 2396 136 0
12 14 47120720 0 1550742898 1148219457 1549890657 1633906508 1700027500
1426092141 1146242387 1229016399 1162100046 1330924371 1429482832 844253517 1398079566 1329877573 1313423693 1095717471
16 18 47120720 0 1162690894 1918981181 1426091637 1347568979 1229344594
1128088908 1934974010 1551069797 1970430292 1398145134 1127232561 1414417743 1397509967 1547322173 1735357008 544039282
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
47120720 0 47127424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
i want a result:
8 10
12 14
16 18
|
|
|
|
|
You already posted this exact question in the ATL/STL forum, and I gave you a suggestion. If you google for "operator overload C++" you will find plenty of samples.
|
|
|
|
|
i was told that these type of questions are to be posted here.
and i did the program..
#include <iostream>
using namespace std;
class matrix{
int **p;
int d1, d2;
int id=0;
public:
matrix(int x=20, int y=20);
int getD_1(){return (d1);}
int getD_2(){return (d2);}
void get_element();
void put_element();
friend int checkAdd(matrix &, matrix &);
friend int checkMul(matrix &, matrix &);
friend matrix operator+(matrix &, matrix &);
friend matrix operator*(matrix &, matrix &);
void operator = (matrix );
~matrix(){
for (int i = 0; i < d1; i++)
delete p[i];
delete p;
}
};
void matrix::operator = (matrix obj){
this->d1 = obj.d1;
this->d2 = obj.d2;
this->id = obj.id;
for(int i=0; i<d1; i++)
for(int j=0; j<d2; j++)
this->p[i][j] = obj.p[i][j];
}
matrix operator+(matrix &a, matrix &b){
matrix temp;
temp.d1 = a.d1;
temp.d2 = a.d2;
temp.id = 1;
if(checkAdd(a, b) == 0){
for(int i=0; i<temp.d1; i++)
for(int j=0; j<temp.d2; j++)
temp.p[i][j] = a.p[i][j] + b.p[i][j] ;
return(temp);
}
else {
cout<<"Matrix addition not possible as rows and coloumn's of given 2 matrices are not equal"<<endl;
return(a);
}
}
matrix operator*(matrix &a, matrix &b){
matrix temp;
temp.d1 = a.d1;
temp.d2 = b.d2;
temp.id = 2;
if(checkMul(a, b) == 0){
int sum=0;
for (int c = 0; c < a.d1; c++) {
for (int d = 0; d < b.d2; d++) {
for (int k = 0; k <b.d1; k++) {
sum = sum + a.p[c][k]*b.p[k][d];
}
temp.p[c][d] = sum;
sum = 0;
}
}
return (temp);
}
else {
cout<<"Matrix Multiplication is not possible as coloumn of 1st Matrix != Row of 2nd Matrix "<<endl;
return(a);
}
}
matrix ::matrix(int x, int y){
d1 = x;
d2 = y;
p = new int *[d1];
for(int i=0; i<d1; i++)
p[i] = new int [d2];
}
int checkAdd(matrix &a, matrix &b){
if(a.getD_1() == b.getD_1() && a.getD_2() == b.getD_2())
return 0;
else return 1;
}
int checkMul(matrix &a, matrix &b){
if(a.getD_2() == b.getD_1())
return 0;
else return 1;
}
void matrix::get_element(){
for(int i=0; i<d1; i++)
for(int j=0; j<d2; j++){
cout<<"m["<<(i+1)<<"]["<<(j+1)<<"] = ";
cin>>p[i][j];
}
}
void matrix::put_element(){
if(id == 1) cout<<"\nThe result of addition of 2 matrices is :"<<endl;
else if(id==2) cout<<"\nThe result of product of 2 matrices is:"<<endl;
for(int i=0; i<d1; i++){
for(int j=0; j<d2; j++){
cout<<p[i][j]<<"\t";
}
cout<<endl;
}
cout<<"\n";
}
int main(){
matrix A(3, 2), B(2, 4), C;
cout<<"Enter matrix elements row by row \n\n";
A.get_element();
A.put_element();
B.get_element();
B.put_element();
C = A * B;
C.showId();
C.put_element();
C = A + B;
C.showId();
C.put_element();
return 0;
}
and thank you for the advice
|
|
|
|
|
Forget about matrix calculations. You need to go and study operator overloading and get that working on a basic class first. Once you understand how to do it correctly so you get no errors, then you can move on to the matrix functions.
|
|
|
|
|
is there anything wrong with the program i have posted before ?
|
|
|
|
|
I don't know; you have to do your own testing. But I find one of the easiest way to debug issues is to create a small test program that just focused on the area that appears not to work. So a small program with a very basic class, that just tests the operator+ overload, would be much easier to understand.
|
|
|
|
|
ok...
thanks for the advice
|
|
|
|