This is a split board - You can return to the Split List for other boards.

Can someone familiar with C++ help me with these problems?

#1Tony_Biggie_PunPosted 9/3/2013 8:39:13 AM
In-class Lab 1 8/29
(Self-Test Exercise #3, Section 1.1 from textbook)

Given the following prototype for a function that computes how long until a given date will occur, answer the questions below.

public static int dateCheck(int year, int month, int day);

The function dateCheck returns zero if the given date has been reached on or before today. Otherwise the return value is the number of days until the given date will occur.

Questions
Suppose you call the method dateCheck(2003, 7, 29).
What is the return value if today is July 22, 2003?
What if today is July 30, 2003?
What about February 1, 2004?

In-class Lab 2 8/29
Write a function to calculate the sum of the elements in an array.
As a start, below is the empty shell for your function. The first parameter, numbers, is the array. The second parameter, size, is the size of the array.

int sum(in numbers[], int size)
{


}

In-class Lab 3 8/29
Given the following class definition, write the main function for a program to create a Car object (with any values of your choice) and display its data (yearModel, make, and speed) on screen.
Extra points if you read the values as input (ask the user to enter year, make and speed)

class Car {
private:
int yearModel;
string make;
int speed;
public:
Car(int y, string m, int s) {yearModel= y; make=m; speed=s;}
string getMake() {return make;}
int getModel() {return yearModel;}
int getSpeed() {return speed;}
void accelerate(int n) {speed += n;}
void brake(int n) {speed -= n;}
};

Unfortunately I had to miss the first day of class so I was not taught how to do these, and I didn't get a textbook yet
---
http://i.imgur.com/Z3MIjNj.jpg
#2Soulesskiller21Posted 9/3/2013 8:54:52 AM
The first question is pretty straightforward (you'll probably need a calendar to get the exact number of days for the third part unless you know the exact number of days in each month)

The second question is just a for loop running through the array. Use the size as the limit and a counter starting at zero and ending when its (1-size)


The third is just making a new instant of a Car object. Been awhile since I did this so the exact syntax escapes me. You basically just use the Car method giving in the class and then do an output for the giving values your teacher wants. If you can remember how to store input for the function the extra credit is pretty easy to get.

I doubt your teacher would teach all of this on day one unless you're taking an advanced c++ class (in which case you should know everything I'm talking about and be fine doing most of it). I could write the code for all this but it would be a lot easier for you in the long run to figure it out on your own (I gave you the tools you'd need to work with now just figure out how to use them)
---
Current Comp: i5-750 2.66GHz|EVGA P55 FTW Edition Mobo|16GB Corsair Vengance DDR3 Ram|Nvidia GTX 570|Win 7 Pro
#3CC RicersPosted 9/3/2013 9:06:51 AM
For the car problem, I'm tempted to use the factory method pattern :P
---
WikiLeaks scandal: WikiLeaks is not a true Wiki!
#4JESSE_PlNKMANPosted 9/3/2013 9:09:54 AM
Not really gonna do your homework for you but...

- the first question doesn't even require coding. This question worries me though - it's so simple I can't imagine it being in a serious college course, plus the fact that you guys are using dates from 2003 implies these problems are from an old textbook, a bit outdated/generic and not really tailored to the class's specific needs. It might just be a Fizzbuzz equivalent though, lol.

- look up how to do for loops.

- making instances is basically "Car * myCar = new Car(2020, "Eclipse", 88)". If you have no idea what this means you are either in the wrong class or really need to look over the lecture notes. As for getting input, there are a few ways - cin/cout is fairly standard, but Google actually considers this a bit sloppy and prefers printf/scanf/etc...
#5Nineteen99Posted 9/3/2013 9:10:55 AM
If your professor (I assume this is a college course?) isn't available, you can check this website out to learn: http://www.cprogramming.com/tutorial/c++-tutorial.html

Like Soulesskiller21 said, I doubt all this was covered in one day. So try contacting your professor to see what you missed, and look that stuff up on Cprogramming.
---
"Words cannot describe how screwed I am..."-Phoenix Wright
Currently Playing: The Sims 3
#6JudgmenlPosted 9/3/2013 9:24:28 AM(edited)
These questions are so wordy.

1.
> 0
> 1
> Difference between July 29 2003 and Feb 1 2004

2.

int sum(in numbers[], int size)
{

int tmp = 0;
for(int i = 0; i < size; i++)
tmp+=numbers[i];

return tmp;

}


3.


//omitting includes

int main(int c, char* argv[])
{

cout << input Make Model Speed << endl;
Car c = new Car( atoi(argv[1]), argv[2], atoi(argv[3]));
cout << Make: getMake() << endl;
cout << Model: getModel() << endl;
cout << Speed: getSpeed() << endl;

return 0;
}


NOTE: I haven't used an C++ in a while, that car Declaration may be wrong, but I don't want to open up something and actually make a program.

Also using atoi() because I'm lazy. inb4random hate and people nitpicking on the typos I made.

---
`1337_FF_GoD` - Presenting the 5DS - Video Games on Motorcycles
http://i.imgur.com/Jb58DQv.jpg - Tanks Nade!
#7JESSE_PlNKMANPosted 9/3/2013 9:13:17 AM
It really isn't much to cover in one day, unless this is an "intro to programming" class for guys just starting out. In which case, I wonder why they don't use Python!
#8Nineteen99Posted 9/3/2013 9:15:27 AM
JESSE_PlNKMAN posted...
It really isn't much to cover in one day, unless this is an "intro to programming" class for guys just starting out. In which case, I wonder why they don't use Python!


My university used to use Java for teaching programming. I actually taught myself quite a bit of C++ when I was in high school, so Java was relatively easy for me. Now they use Python for the intro classes, and Java for mid-high classes.
---
"Words cannot describe how screwed I am..."-Phoenix Wright
Currently Playing: The Sims 3
#9Ch3wyPosted 9/3/2013 9:16:56 AM
It's really crucial that you understand how to do these rather than just find the answers.

Not being able to find out the first one is really bad. What are you having trouble understanding here?
---
Every time you point out that something is an opinion Jesus shoots a kitten in the face.
#10JESSE_PlNKMANPosted 9/3/2013 9:19:45 AM
Uh Judgment,

"int tmp+=numbers[i];"

is incorrect. Perhaps you should test out your code in your own IDE before posting... you also have a typo at "in numbers[]". Also using "lel" outside of its home site is considered cancerous.