>>But I have no idea how can I integrate one list onto another.
What requirements comes to mind when you think this?
>>But I have no idea how can I integrate one list onto another.
What requirements comes to mind when you think this?
Use sstream;
#include<sstream>
#include<string>
using namespace std;
int main(){
stringstream converter;
string str= "3.14";
converter << str ; //put in string
float PI = 0;
converter >> PI; //put out float
return 0;
}
At this stage(I am assuming), it may be easier( for you) to create a function, like so :
class Timer
{
int h,m,s;
public :
void getTime() { cin >> h >> m >> s; }
}
Something like this : ?
1) Create a result list
2) Merge list A and list B
3) copy result list to list A, while making sure that list A has enough add at each insertion.
* * * * * # # # 1
* * * * # # # # 2 ROW
* * * # # # # # 3
realize that there are 5 '*' the 4 '*' then 3 '*' after each line.
On the other side, there are 3 '#', then 4 '#' then 5 '#'.
What does this tell you about where to start and end for each symbols.
First create a constructor and initialize all member variables.
Make sure you initialize all variables before using them.
>>If not, it would take a pretty decent about of math power to turn a c-string into a float.. perhaps the math would be less intense isolating the first digit of a float...
Won't be that hard, just need to know two things,
1) The isolated Number
2) The degree of that Number;
Neither.
Its should look something like this :
~LinkedList(){
List * temp = head;
while(temp != null){
temp = temp->next;
delete head;
head = temp;
}
}
>>I need to use the input data after it is validated in float form, is it possible to make the string data a float number after it is validated?
Can you use sstream library?
or do you have to do it manually?
Not exactly sure if this will help but the equation to a circle is :
//Cartesian coordinate
X^2 + Y^2 = R^2
//polar coordinate
//R = radius
sin^2(x)* R + cos^2(X) * R = 1
how about getting the input as string( or char array if you can't use string).
string num = "";
cin >> num;
if( validate(num) == false ) //Error ...
Validate function :
bool validate(string num)
{
if( num[0] < '0' || num[0] > '9') return false;
return true;
}
Haven't tried it but it should work.
are you inputting it like this(exactly) :
input : 123456789
or are you putting it like this
input : 1 2 3 4 5 6 7 8 9
The seconds one should work.
Do you mind if I post your code here?
Did you try it out?
Hint :
totals[die1 + die2]++;
should be :
totals[roll] = die1 + die2;
and make sure totals can hold up to 1000 dice roll information.
where is the position of the box relative to ? Its center ? Edge ?
>>1) The format the user should be entering his matrice should be:
1 2 3 4 5 6 7 8 9 'ENTER'
right now it is 1 'ENTER', 2 'ENTER', 3 'ENTER' ... etc all the way to the 9th number.
what happens if you just put 1 2 3 4 ... <enter> as your input, it should work.
2) if you look at the output I am currently getting at the bottom of my first post you will see that there is a '+' sign and an '=' sign after each row, i need to make it so that there is only 1 of each aligned with the center row.
so you want :
1 2 3 1 2 3 2 4 6 //and so on
4 5 6 + 4 5 6 =
6 7 9 7 8 9
if so then just do a test case(i.e if/else) when row is 2 and column is the last column.
if(row == 2 && col = lasCol)
cout << A[i][j] <<" + " << endl;
for the other matrix you would have to change the plus to equal sign.
Hint, when you declare a function prototype inside a class, make sure it
has the same signature outside of its class, that is when you define it.
>>1) the style in which the user inputs their numbers for each 3x3 matrix should be - enter all 9 #s and then press enter... as opposed to enter a # press enter (9x)
Ok, whats the problem with this?
>>2) the only place i know where to put the '+' and '=' sign makes it print each time... where should i place it to only print in the center of the Matrices?
not sure what you mean?
>>3) part of the assignment is to use the void function, i never utilize it in my main, im lost as to where exactly i should put it in
that void function adds matrices, so call it before you print out all the
result, like addMatrices(matrix1,matrix2,resultMatrix);
then you can print out the results.
Can you insert the values the linkedlist contains into an array and then
sort it ?
hint :
int x = 0, y = 0;
int t = x + y;
is not the same as
int x, y;
int t = x + y
v1 an v2 represent vectors, so if v1 = <i,j,k> and v2 = <i,j,k> then
the distance between them is (v1 - v2).length.
Remember the length is the magnitude of the vector.
print out the sum, cout<<sum << endl;
This is problematice :
int sum = 0;
int x=0; // you declared it inside the for loop below
for(int x=0; x<3; x++);
{
x=x+sum; //what happened to num array?
cout << "The total is: ";
cin >> x;
}
change to :
int sum = 0;
for(int x=0; x<3; x++);
sum = sum + num[x];
cout << "The total is: " << x << endl;
The distance between two vector is given by (v1-v2).length();
Your return type should be similar to the parameters passed.
And welcome!
If thats your case then you should declare a pure virtual function like so :
virtual string getName() = 0;
That means that this class is a ABC class and all subclass should
redefine the method getName().
Thanks for helping me out firstPerson !
Can I ask though, I see the base class in your example has a datamember called 'name'.
My base class however is an abstract base class.
Should I add a datamember to my base class even though it won't ever be used?
You should not add data variables to Abstract Base class(ABC) if it wont be used in its subclass.
change
float points (x1, x2, y1, y2)
to
float points (float x1, float x2, float y1, float y2)
also your distance formula is wrong :
distance = sqrt(x2-x1) + (y2-y1);[/code]
the distance between two points is given by the formula :
D = sqrt( (x2-x1)^2 + (y2-y1)^2 )
You shouldn't have to, as long as you initialize you variable upon
deceleration.
You can always do this if you like :
const int NOT_INITIALIZED_VALUE = 0;
int i = NOT_INITIALIZED_VALUE ; //set to default value
int j = 4;
if(i == NOT_INITIALIZED_VALUE ) cout <<" i is not initialized\n";
if(j == NOT_INITIALIZED_VALUE ) cout <<" j is not initialized\n";
Here is another one, but it delays process.
#include <iostream>
#include <ctime>
using namespace std;
void delay(int milliSec){
const unsigned int clk_strt = clock();
while(clock() - clk_strt < milliSec)
continue;
}
int main(){
for(int i = 0; i < 5; i++)
{
delay(1000);
cout<< (i+1) << " seconds has passed\n";
}
}
>>I'm storing base class pointers in a vector, the pointers are pointing to objects from the derived class ( Leads ).
>>I'm unable to access the 'getter' functions of the derived class. How can this be done?
It seems like you need the use of virtual functions. The error message says what it means, you have not defined a getDate function in you
base class.
Here is an example of something that might help you :
#include <iostream>
#include <vector>
#include<string>
using namespace std;
class Base{
private :
string name;
public:
Base() : name("") { };
Base(const string str) : name(str) { };
virtual const string getName() {
return name;
}
};
class Derived : public Base{
string myName;
public:
Derived() : Base(), myName("") { }
Derived(const string derStr) : myName(derStr) { }
Derived(const string baseStr, const string derStr) : Base(baseStr) , myName(derStr) { }
const string getName() {
return myName;
}
};
int main()
{
vector<Base*> baseVec;
Base b1("base 1");
Derived d1("derived 1");
Derived d2("derived 2");
baseVec.push_back( &b1);
baseVec.push_back( &d1);
baseVec.push_back( &d2);
for(unsigned int i = 0; i < baseVec.size(); i++){
cout << baseVec[i]->getName() << endl;
}
return 0;
}
I don't know what school you finished and what books you've read but after this reply I'm saying that you have very little knowledge of c++ syntax and of c++ as whole.
Whats up with the attitude? I tried to help, but instead you insist that you are an asshole.
First:
int *p = &r; //a pointer to a reference
no its not a pointer to a reference. Just read it p is a pointer to int. What you're doing is you assigning an address of variable referenced by r.
Its a pointer to a int, in which the int is a reference to another variable, thus it follows that p is a pointer to a (int)refrence
And as for your explanation:
what in the opposite way. Why is it ok to have:
How about you fix your grammar before you ask question.
int*& p;
but not according to you:
int&* p;
If ref and pointers are according to you this same why second doesn't it make sense and the first one does?
Again, are you talking English, or are you still in middle school ?
I did not say reference is the same as pointer, I said a pointer is sort of like a reference where when you change the reference value or a pointer value, the original value changes.
int* &a; //reads as a pointer that is a reference //Absurd
int& *b; //read as a reference that is a pointer ILLEGAL
why would you even …
POINTERS TO REFERENCES ARE NOT ALLOWED IN C++.
.
Your words are misleading because a pointer-to-a-reference means
int a = 3;
int &r = a;
int *p = &r; //a pointer to a reference
what you really mean :
int x = 3;
int & *a = &x;
Is invalid because in sort a reference is like a pointer, so
it really does not make sense to have a reference and a pointer variable. They both do the same thing, ultimately, so there is no need.
First off when you have a reference to a Data_Type in a class,
they have to be initialized by the initializer list.
Also what does it mean to have a reference of the following :
int &a = 3;
You are saying that a is a reference to a literal, and thats an error in c++;
But what about const reference :
const int& a = 3;
This is a valid code in c++. C++ allows const reference, but not for
member variables.
With that in mind lets see what you are doing :
class Nunu
{
private:
const string& _my_name; //const reference, must be initialized in the initializer list
public:
Nunu():_my_name("UNNAMED"){}; // BUG, because a reference to a literal , which goes out of scope soon!
Nunu(const string& the_name):_my_name(the_name) //ok for now as long as the_name is not a literal, because _my_name wont be valid as it will run out of scope.
{
}
string name()const
{
return _my_name;
}
};
int main()
{
Nunu* p = new Nunu[5]; / ok, but what happens to the string reference?
Nunu a("a"); //does not work as you might
Nunu b("b");//see above
Nunu c("c"); //see above
p[0] = a; //now you are making a copy from a to p[0], but p[0] takes a const string& ref so this is invalid
p[1] = b; // see above
p[2] = c; // see above
for (int i = 0; i < 3; ++i)
{
cout << …
>>Is it possible to have pointers to references in c++
Yes its possible, long as you watch out for const.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int X = 4;
int &y = X;
int *p_to_y = &y;
cout<<"X is " << X<<endl;
cout<<"Y is " << y<<endl;
cout<<"p_to_y is " << *p_to_y << endl << endl;
X = 10;
cout<<"X is " << X<<endl;
cout<<"Y is " << y<<endl;
cout<<"p_to_y is " << *p_to_y << endl << endl;
y = 15;
cout<<"X is " << X<<endl;
cout<<"Y is " << y<<endl;
cout<<"p_to_y is " << *p_to_y << endl <<endl;
*p_to_y = 20;
cout<<"X is " << X<<endl;
cout<<"Y is " << y<<endl;
cout<<"p_to_y is " << *p_to_y << endl;
}
Your wording is a little ambiguous, how about an example?
#include<iostream>
#include<windows.h>
int main(){
string str = "hello";
cout<<str<<" ";
Sleep(1000); //wait 1 second
cout<<"world\n";
return 0;
}
Maybe this will help :
#include<iostream>
using namespace std;
int main()
{
float pi = 3.141579;
cout.precision(5); //set precision to output
cout << pi << endl;
cout.precision(3);
cout<<pi<<endl;
return 0;
}
I thought you purposely gave him a dud answer so he would hand it in. Well done you had me fooled.
Maybe, I don't remember what I was thinking at that time.
How to declare an array in c++ :
int Array[4] = {1,2,3,4};
const int SIZE = 6;
float Array[SIZE] = {0}; //set all elements to 0
char Array[5] = {'1','2','3','4','\0'}; // "\0" is the null character and an array of char should end with it.
int Array[]; // invalid form
int[] Array; //invalid form
Don't just dump your assignment and expect to get the source code to
your problem, thats so ignorant.
Lol, I was high when I posted that, sorry.
Garbage in, garbage out. Before you spend a lot of time analyzing your functions to see where the logic error is in calculating the lowest, highest, and average, loop through your array and make sure it's storing what you think it is.
i.e the problem first occurs somewhere in here :
while (grades[pos] != -99)
{
grades[pos] = numberOfGrades; // store grade read in to next array location
pos ++; // increment array index
cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;
cin >> grades[pos];
}
Kind of, you will have to do an offset.
char convertNumericToLetter(int i)
{
if( i < 0 || i > 26 ) return 0;
else return char('a' + i);
}
Maybe, try using code tags so we can see it better.
1st) Read post 1, although if you PM, someone that knows a little math, he might help you.
2)
Let A = r+5(r-2)=28
Let B = 3(r+4)+5(r+2)=102
//Break down A
A = r+5(r-2) = 28
= r + 5r - 10 = 28 //distributive rule
= 6r - 10 = 20 //add like trms
= 6r = 20 + 10 //remember switching numbers to the opposite sides mean change its operatorion from + to minus, * to / and vice-versa
so, 6r = 20 + 10,
6r = 30
r = 30/6 = 15/3 = 5
//Break down of B
Let B = 3(r+4)+5(r+2)=102
B = 3r + 12 + 10r + 20 = 102 //Distributive property
= 3r + 10r + 12 + 20 = 102 // re-arrange like terms
= 13r + 32 = 102 //add like terms
= 13r = 102 - 32 //bring together like terms
= 13r = 70
= r = 70/13
You are getting "close, but no cigar".
Here is a hints :
Try changing the prototype of :
void processScore(char& c);
to
char processScore(int& numberGrade);
It accepts a number such as 82, and should return a value associate with the number.
You may use it like this :
int myGrade = 87;
//which maybe prints B or B+, depending on your choice
cout << processScore(myGrade) << endl;
or you can use it like this :
//always initialize
int average = 0;
char letterGrade = 0;
processScore(&average);
letterGrade = processScore(average);
cout <<"Your Grade is:" << average << endl;
cin.get(); //use this rather than system pause;
return 0;
Just remember that when rotating an object, you should rotate the world in opposite direction to make the world coordinate the same relative to that object.
Yes. Try declaring a constructor that sends a message when its destroyed
to see how it happens.
Is it just me because I am seeing only 1 class diagram of the following :
Person
(attributes)
person_name:string
person_id:int
(operations)
getName(char)
getID(int)
In anyways, to create a class diagram, you have to think about what a class represents, and what it holds.
What is your definition of a class, no cheating.
What should it hold, name technical terms if you know, like attributes and properties.
And how should it interact with other classes?
After you have answer this question you should be able to create a complete class diagram.