C/C++ :: Simulating Falling Object Using Vectors

Mar 11, 2014

I'm just having a bit of troubles on getting my code to work from this psuedo code - It has been asked for the object to be set at at least a height of 30 units (in the y property). -

#include <iostream>
#include <Windows.h>
#include <conio.h>
using namespace std;
struct Player {
float position ;
float velocity ;

[Code] ....

Attached image(s)

View 14 Replies


ADVERTISEMENT

C/C++ :: Falling Object Error When Coding

Mar 4, 2014

Write a program that computes how many feet an object falls in 1 second, 2 seconds, etc., up to 12 seconds.

1.Have a procedure called FallingDistance which has one input parameter, seconds, and one output parameter, distance.
2. Compute the distance in feet an object falls using this formula: d = ½ gt2
(where g = 32.2)
3. The main program should call FallingDistance within a loop which passes the values 1 through 12 as arguments.
4. Print a table with seconds and falling distance in feet.

Sample Output (This program has no input)

Seconds Distance
================
1 16.1000
2 64.4000
3 144.9000
4 257.6000
5 402.5000
6 579.6000
7 788.9000
8 1030.4000
9 1304.1000
10 1610
11 1948.1000
12 2318.4000

In C++, the procedure is called a function. Instead of using an output parameter, your C++ function FallingDistance should return a result of type double. This is what I created:

#include <iostream>
#include <cmath>
#include <string>
using namespace std;
const double g =32.2;
double fallingDistance(double);

[Code] ....

which gave me this error:

1>------ Build started: Project: Lab 6, Configuration: Debug Win32 ------
1> Source.cpp
1>c:usershanahdocumentsschoolprogamming ilab 6lab 6source.cpp(27): error C2065: 'fallingdistance' : undeclared identifier
1>c:usershanahdocumentsschoolprogamming ilab 6lab 6source.cpp(36): error C2065: 't' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

View 4 Replies View Related

C++ :: Pointer Class Object Vectors

Aug 4, 2013

#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
struct bop {
string realname; //real name

[Code] ....

Okay, so first thing's first. The program will not compile due to lines 39-45. If I were to change those pointers into regular objects, it will not change the values of my class object. So what is the right way to do this?

I want the user to be able to input the # of employers/programmers into the system. But I cannot do that with an array of classes because when declaring an array; the array size must be constant.

View 6 Replies View Related

C++ :: How To Store The Same Instance Of One Object In Multiple Vectors

Feb 4, 2015

If I have a class object and multiple vectors, how do I make sure I store the same instance of that object in both vectors? For instance:

Object object;
std::vector<Object> vectorOne;
std::vector<Object> vectorTwo;
vectorOne.push_back(object);
vectorTwo.push_back(object);

Are the objects in both vectors the same instance of the object? Like if I called vectorOne[0].setValue(somethingDifferent); would the value be changed for the object in both vectorOne and vectorTwo? If not, how do I make sure that I only have one instance of the object I'm trying to store in multiple vectors?

View 15 Replies View Related

C++ :: Switch Statement Falling Through All Cases

Jan 16, 2014

I was getting errors and I looked into the error and it told me to fix it by adding Code: { } in my case statements. I did, it compiled but fell through the whole thing. Lets say I enter 1, it outputs the was not found 5 times in a row.

Code:
void addressbook::EditNameOrDate() {
std::cout << "Enter 1 to Edit the contacts First Name: " << "
";
std::cout << "Enter 2 to Edit the contacts Last Name: " << "
";
std::cout << "Enter 3 to Edit the contacts Street Address: " << "

[Code] .....

View 8 Replies View Related

C :: Simulating Random Dice Roll As A Basis For Chutes And Ladders Game

Jan 24, 2014

I am trying to simulate a random dice roll as a basis for a chutes and ladders game

Code:
int main {
int i = 0, diceroll;
while (i>5) {
diceroll = 1+rand()%6;
i++;
}
return 0;
}

However the numbers get don't seem to be random, it always starts off with 6,6,5.. then its random.

View 10 Replies View Related

C++ :: Animated Images Falling From Top Of Screen - Drag These Items Into A Basket

Apr 18, 2012

Im developing a game where i need 18 animated images to fall into view from the top of the screen with 14 of type A visible and 4 of type B. I then need to be able to drag these items off screen or into a basket at the bottom of the screen.

My current issues are:

I cant seem to drag the images off screen or to the basket when they are animated.I cant make the images fall randomly with delay between them.I was able to make the 18 appear, but not as listed above in the description with 14 of type A and 4 of type B.

View 2 Replies View Related

C++ :: List Of Vectors (vector Of N Vectors Of M Elements)

Mar 19, 2014

I create a list of vectors (a vector of n vectors of m elements).

std::vector <std::vector <int> > vsFA (n, std::vector<int>(n));

How I assign values? I try below, but not worked

void armazenaFA( std::vector <int> &vFA) // this function only knows about vFA
{ vsFA[n] [m]= simTime().dbl();
OR
vsFA[n].push_back(simTime().dbl());
}

View 1 Replies View Related

C++ :: Create Two Vectors And Then Loop Through The Vectors

Sep 19, 2014

This is probably a very basic question, but I need to create two vectors and then loop through the vectors and output each pair that is found.

The user will input min1 and max1 with step1 for the first vector and min2 and max2 and step2 for the second vector. Then the loops will go through and return the combinations will return each pair of the two vectors.

So if I input min1=1 and max1=10 and step1=1 and same for vector two the return would be:

[1,1]
[1,2]
.
.
.
[10,10]

This is for part of a homework assignment, but I can't continue on the assignment without first getting this simple part to work.

View 1 Replies View Related

C++ :: Simulating 2D Array With 1D Array?

Jun 29, 2014

I'm trying to simulate a 2D array using a 1D array. The array looks like the following:

const int MAP_WIDTH = 20;
const int MAP_HEIGHT = 10;
const unsigned char MAP[MAP_WIDTH * MAP_HEIGHT + 1] =
{
"00000000000000000000"
"11111111111111111110"
"01111111101111111110"
"01111111101111111110"
"01111110000011111110"
"01111111101111111110"
"01111111101111111110"
"01111111101111111110"
"01111111111111111111"
"00000000000000000000"
};

If I want the index of a certain coordinate, say {10,5}, I would simply do:

int index = MAP_WIDTH * 5 + 10

What I wonder is, how would I go the other way around? If I have an index, how would I get the {X,Y} coordinate matching that index?

View 4 Replies View Related

C++ :: Will Copy Constructor Does Object Initialization Using Another Already Created Object

Mar 16, 2013

will copy constructor does object initialization using another already created object? I understand that it can be applied for object initialization and not for assignment.Is it correct?

View 10 Replies View Related

C# :: Method Is Overwriting Both Instance Of Object And Original Object

Jul 3, 2014

I have a method to take a Tile object and make an instances of it based on some data from the original object. Than it is suppose to manipulate the a specific instance and save the results. The first loop through it works but it changes all instance as well as the base.

public static int recurse(int count, Tile[,] b,Huristic h,int check) {
if (check==1) {
boardState.Add(B)/>;
return check;
} if (check == 0)

[Code] .....

View 6 Replies View Related

C++ :: Importance Of Static Object In A Class And How They Are Different From General Object

Dec 13, 2012

#include "B.h"
class A {
public :
A()
{
s_b = new B();
b = new B();

[Code] ....

In my project i have seen static object as above . But not able to know what is the exact use of it and how they are different from general object .

View 2 Replies View Related

C++ :: What Can't Non-const Object Receive Temporary Object

Sep 11, 2014

a function returns a temporary object like

int myfun(){
int x = 0;
return x;
}

this function will return a temporary integer now void fun1(const int & num); this function can receive from myfun().BUT void fun2(int & num); this function cannot receive from myfun() Why is that, Moreover what is lifetime of a temporary object like one returned in myfun() ???

View 7 Replies View Related

C# :: Constructor Object Reference Not To Set Instance Of Object

Mar 28, 2014

I am trying to use web api in order to return custom json response keys. For this i have return a custom class to return json response

Custom Class:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

[Code].....

View 2 Replies View Related

C Sharp :: Object Reference Not Set To Instance Of Object?

May 4, 2013

I have a combobox with Items 1024
2048
4096
8192

String cach = form.comboCache.SelectedItem.ToString();

I am using the above code to retrive an item selected by user,But this line is giving an exception "Null Reference Exception, Object reference not set to an instance of an object"

View 1 Replies View Related

C# :: Object Reference Not Set To Instance Of Object?

Mar 28, 2014

I am using session to pass object from controller to custom class in MVC Web API. here is my code, i am getting error at session.

public HttpResponseMessage Get()
{
var person = db.Persons.ToList();

[Code]....

View 1 Replies View Related

C/C++ :: Get Reference To Text Object With The Name Of Object?

Aug 23, 2013

In Visual Studio 2010 C++
I have a series of existing text objects
The text properties names are
item1_lbl,
item2_lbl,
item3_lbl,
….

Based on a selection I want to change an object. I generate the name of the object I want to change in a string so from this string is there a way to get a pointer to the correct text object that is same name?

View 3 Replies View Related

C/C++ :: Any Way To Have 2 Vectors Mix Together?

Mar 27, 2013

I want to add 2 vectors to print out so that there on the same line. What I am trying to make is an inventory system that will use 2 vectors to keep the pounds of the item and list the 2 vectors on one line.

(I am using Microsoft Visual C++ 2010 Express)

Like this:

0. empty 0
1. empty 0
2. empty 0

etc...

Right now it looks like this:

0. empty
0. 0

The code:

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>  
using namespace std;  
int main() {
    vector<string> inv;

[Code] ....

View 14 Replies View Related

C/C++ :: How To Add Strings To Vectors

Apr 19, 2012

I have a vector I want to add book titles to, then i want to print my updated vector. This is best I have come up with but the program fails at the getline line. why?

string book;
cout << "Enter book to add: "<< endl;
getline(cin, book);
books.push_back(book);
for(int i = 0; i < books.size(); ++i) {
cout << i+1 << ". " << books[i] << endl;
}

View 1 Replies View Related

C++ :: Starting Vertex Array Object At Index Of Vertex Buffer Object

Sep 22, 2014

I'm trying to figure out how I can create a vertex array object at offset of a vertex buffer object.I've created the buffer object. I'd like the "texs" idnex data to start at the texture coordinate content of the vertex_t structure.

Type definitions:

struct vertex_t {
vector3d_t position;
float s; // Texture coordinate s
float t; // Texture coordinate t
};

Code so far:

// How do I make this start at a certain spot of the VBO?!
glVertexAttribPointer(texs, 2, GL_FLOAT, GL_FALSE, sizeof(vector3d_t), nullptr;
//...

View 1 Replies View Related

C++ :: Calculate The Angle Between Two Vectors

Feb 20, 2014

My question is not in c++ programing , but because my aim is to make code that calculate the three angles between two vector i ask my question here

So as the title i have three point that create two vector and I want to get the angles in x,y and z of the point2

I used crosproduct that give me one angle without axe , I don't know in which axe this angle

My aim is the three angles for the 3 axes ....

View 7 Replies View Related

C++ :: Manhattan Distance Between Two Vectors

Mar 25, 2014

I can't figure out the error in this code; it compiles but returns rubbish.

serge
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

[Code] ......

View 7 Replies View Related

C++ :: Quaternion For Rotating Vectors

Dec 28, 2013

I try to use quaternion to rotate one(and later more!) 3d-vectors in a general manner.

i read in wikipedia, that the general calculation goes with:

vector_rot = quaternion * vector * quaternion_compl.conj.

I used the class of irrlicht [URL] .... to do the calculations.

there is no premade function in this class to rotate vectors through this quaternions, so i just tried to it this way:

irr::core::vector3df v1(1,0,0);
irr::core::quaternion a1(2,3,4,6);
a1.normalize();
irr::core::vector3df result2(a1.X*v1.X*(-a1.X),a1.Y*v1.Y*(- a1.Y),a1.Z*v1.Z*(-a1.Z));

result2 should then be the rotated vector, but it does not work. i dont know how to explicitely write down the rotation specification in this topic.

View 7 Replies View Related

C++ :: Using Vectors For A Clip / Cache

Apr 19, 2013

I'm trying to make it like a game. You would fire your gun, then have the option of reloading. If you run out of ammo and try to fire...it will automatically come out of your cache. Anyone who played a 3rd or first person shooter knows what I mean. I thought vectors would be the best course of actions since they can remove and add elements with ease. One of the many problems I have is subtracting the Hand Guns current ammo (size) from its maximum (capacity) to see how much to A. push_back into the clip and B. pop_back out of the cache. Can size() and capacity even be subtracted? Here's the code with what I believe to be all the possibilities.

#include<iostream>
#include<vector>
using namespace std;
int main(int argc,char** argv) {
vector<int> HG_cache (36,1);
vector<int> HG_clip (12,1);
char user_input;

[code]....

View 1 Replies View Related

C++ ::  NCurses Outputting Vectors

May 19, 2013

The following code works perfectly with "normal" C++

#include <iostream>
#include <vector>
int main() {
std::vector <std::string> hello {

[Code] ....

This prints "HELLO" on the screen. A function a bit more like NCurses is:

for (std::vector <std::string>::const_iterator it = hello.begin(); it != hello.end(); it++) {
std::string temp = *it;
std::cout << temp.c_str() << std::endl;
}

This still works with "normal" C++. Now, how do I get this working with NCurses? I tried

#include <curses.h>
#include <string>
#include <vector>
int main() {
initscr();

[Code] ....

But this just gives me an empty screen.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved