im the biggest noob ever and i need mad help (shuld be easY)

Ask for help with your homework/assignments in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

im the biggest noob ever and i need mad help (shuld be easY)

Postby C++noob » Fri Oct 03, 2003 8:34 am

well guys i need u to write this easy program for me because i am a complete retard stuck in class without a clue... this is what i get ::

the height of an object dropped from a starting point of 100 meters is given by the equation h=100-4.98*t*t .. where t is the time in seconds. write a program that ask the user for a time less then 20 seconds and displays the height of the object at that time using this formula. the program output should look similar to

enter the time :
the object is at :


thankyou so much u have no idea.. and if ur relli good at this stuff i get 5 project to do a day .. ill keep them comin :P
C++noob
 
Posts: 5
Joined: Fri Oct 03, 2003 8:28 am

Postby twm » Fri Oct 03, 2003 9:19 am

You're asking us to do your work for you and cross-posting it? Geez...
The information given in this message is known to work on FreeBSD 4.8 STABLE.
*The above statement is false if I was too lazy to test it.*
If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
twm
 
Posts: 22
Joined: Mon Sep 29, 2003 2:38 pm

Postby RecursiveS » Fri Oct 03, 2003 12:28 pm

You may get someone to write your code for you - but it will probably cost you quite a few dollars - best of luck. :)
User avatar
RecursiveS
Site Admin
 
Posts: 1236
Joined: Thu Sep 18, 2003 8:33 am
Location: Dorset, UK

Postby RecursiveS » Fri Oct 03, 2003 12:30 pm

Oh, and pleasedon't double post - it's very annoying.

:)
User avatar
RecursiveS
Site Admin
 
Posts: 1236
Joined: Thu Sep 18, 2003 8:33 am
Location: Dorset, UK

Postby jgbauman » Fri Oct 03, 2003 2:32 pm

Since you asked so nice and showed so much effort, here is an solution ;-)

Code: Select all
(begin
(display "enter the time : ")
(let
  ((t (read)))
  (display "the object is at : ")
  (display (- 100 (* 4.98 t t)))
  (display "\n")))
User avatar
jgbauman
 
Posts: 358
Joined: Sat Sep 27, 2003 9:00 am

Postby Alvaro » Fri Oct 03, 2003 3:19 pm

jgbauman's solution is nice. All you have to do now is write a Lisp interpreter in C++ and hand it over to your teacher.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Alvaro » Fri Oct 03, 2003 4:24 pm

This program is not very portable. But I still like it.
Code: Select all
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>

using namespace std;

enum {EXIT,PRINTS,PRINT,INPUT,PUSH,PUSHV,MULTIPLY,DIVIDE,SUBSTRACT,POPV};

int p[]={
   PRINTS,(int)"enter the time: ",
   INPUT,(int)"t",
   PUSH,100,
   PUSH,498,
   PUSH,100,
   DIVIDE, 
   PUSHV,(int)"t",
   PUSHV,(int)"t",
   MULTIPLY,
   MULTIPLY,
   SUBSTRACT,
   POPV,(int)"v",
   PRINTS,(int)"the object is at: ",
   PRINT,(int)"v",
   PRINTS,(int)"\n",
   EXIT
};

int main(void){
   map<string,double> v;
   stack<double> s;
   int i=0;
           
   while(1){
      switch(p[i++]){
      case EXIT:
         return 0;
      case PRINTS:
         cout << (char *)p[i++];break;
      case PRINT:
         cout << v[(char *)p[i++]];break;
      case INPUT:
         cin >> v[(char *)p[i++]];break;
      case PUSH:
         s.push((double)p[i++]);break;
      case PUSHV:
         s.push(v[(char *)p[i++]]);break;
      case MULTIPLY:
         {double t=s.top();s.pop();s.top()*=t;}break;
      case DIVIDE:
         {double t=s.top();s.pop();s.top()/=t;}break;
      case SUBSTRACT:
         {double t=s.top();s.pop();s.top()-=t;}break;
      case POPV:
         v[(char *)p[i++]]=s.top();s.pop();break;
      }
   }   
}

User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Jimbo » Fri Oct 03, 2003 5:07 pm

hm... Alvaro's code is cheaper than mine, but your teacher will have to be completely senile to not notice anything about it...

starting price for something like this is $50 btw... (and if you are willing to pay, you'll have almost immediate results)
User avatar
Jimbo
 
Posts: 601
Joined: Thu Sep 25, 2003 6:48 pm
Location: Seattle

Postby Justin » Sat Oct 04, 2003 12:51 am

nice alvaro. here's something a bit more portable

Code: Select all
<?php

function show_form() {
  echo "<form action=\"\" method=\"post\">\r\n  Enter the time:&nbsp;&nbsp;&nbsp;<input type=\"text\" name=\"time\" size=\"40\"><br><input type=\"submit\" value=\"Go\">\r\n</form>";
}

if ( !isset($_POST['time']))
  die(show_form());

$t = $_POST['time'];

if ( !ctype_digit($t)) {
  echo "Data must be numeric\n";
  die(show_form());
}

if ($t > 20 || $t < 1) {
  echo "Enter a time between 1 and 20\n";
  die(show_form());
}

$h = 100-4.98*$t*$t;

echo "The object is at: $h";
?>


I like how he throws us a bone at the end.

and if ur relli good at this stuff i get 5 project to do a day .. ill keep them comin
User avatar
Justin
 
Posts: 158
Joined: Tue Sep 30, 2003 10:07 am
Location: CA

Postby Jimbo » Sat Oct 04, 2003 6:14 pm

just an afterthought but... either my mental math sucks, or the object hits the ground at ~sqrt(20) sec...

or does it fall into a nice little hole?
User avatar
Jimbo
 
Posts: 601
Joined: Thu Sep 25, 2003 6:48 pm
Location: Seattle

A C++ solution

Postby foolguitardude » Sat Oct 04, 2003 6:18 pm

Code: Select all
#include <iostream.h>

int main()
{
   double seconds = 0;
   double total = 0;
   cout<<"Please enter a number lower than 20: ";
   cin>>seconds;
   cout<<"\n";

   if(seconds < 20)
   {      
      total = (100-(4.98*seconds))*seconds;
      cout<<"The object is at: ";
      cout<<total;
      cout<<"\n\n";
   }
   else
   {
      cout<<"Invalid input\n\n";
   }
   return 0;
}


This is the last one you get for free.
foolguitardude
 
Posts: 2
Joined: Sun Sep 21, 2003 6:21 pm

Postby MXP » Sat Oct 04, 2003 11:49 pm

For free? That code is incorrect anyway. There is no iostream.h in C++
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby jgbauman » Sun Oct 05, 2003 2:32 am

Jimbo wrote:just an afterthought but... either my mental math sucks, or the object hits the ground at ~sqrt(20) sec...

or does it fall into a nice little hole?


Newest scientific studies showed that in contrast to the now general believe, earth is indeed flat. And if you drop an object 100 meters above the edge. It simply falls of the earth and so can have negative heights. Simple, eh?

And if you don't believe me, noob's formula proofs it.
And since it can be implemented on a computer and computers are always right (and operated by people in white lab coats, as shown in most movies about early computers) it must be true.
User avatar
jgbauman
 
Posts: 358
Joined: Sat Sep 27, 2003 9:00 am

Re: A C++ solution

Postby omnius » Sun Oct 05, 2003 3:35 am

foolguitardude wrote:
Code: Select all
#include <iostream.h>

int main()
{
   double seconds = 0;
   double total = 0;
   cout<<"Please enter a number lower than 20: ";
   cin>>seconds;
   cout<<"\n";

   if(seconds < 20)
   {      
      total = (100-(4.98*seconds))*seconds;
      cout<<"The object is at: ";
      cout<<total;
      cout<<"\n\n";
   }
   else
   {
      cout<<"Invalid input\n\n";
   }
   return 0;
}


This is the last one you get for free.


Minor point on style. You declare total at the start of main but don't use it until further down your code. Not only that, but if an invalid number of seconds is entered you don't use total at all. Consider declaring total in the smallest scope necessary, which in this case is inside the block of the if statement. If you declare it thus:

Code: Select all
   if(seconds < 20)
   {      
      double total = (100-(4.98*seconds))*seconds;
      cout<<"The object is at: ";
      cout<<total;
      cout<<"\n\n";
   }


then you reduce the scope of total to just where it's used, and initialise it with a value at the point of declaration rather than initialising it with zero before you need it.

It's not such a big deal in a small simple program of the type posted here, but these are good habits to form.
omnius
 
Posts: 496
Joined: Wed Sep 24, 2003 12:03 pm

Postby Justin » Sun Oct 05, 2003 12:16 pm

very well put
User avatar
Justin
 
Posts: 158
Joined: Tue Sep 30, 2003 10:07 am
Location: CA

Next

Return to Homeworks

Who is online

Users browsing this forum: No registered users and 4 guests

cron