CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2006
    Posts
    3

    Help with a MidTerm - Simple programming

    Hi, I'm taking an online C++ course at school and my instructor doesn't know much about C++. The course was basically "read a book and figure it out yourself" type of course.

    I have to turn in a midterm by Jan 18. It's scripting something from scratch, of course, but I really didn't learn how to do that. I have some grasp of the language, but it's very little. I was wondering if anyone could guide me and point out any errors to me or show me any methods I should use.

    This is what was posted on the course website:
    Midterm Project:

    As the project for the midterm, please write a program that will compile in C++ that includes:

    - Functions and variables
    - Classes and Constructors
    - Operator Overloading
    - Initialization and Assignment

    The output can be anything you would like but should be properly coded. Submit your coding project to the instructor for grading and recording. Grades will be based on the output after the instructor compiles them.

    This is what I have so far:

    Code:
    #include <iostream.h>
    
    int main () {
    
      cout << "Enter a degree of temperature in Celsius: ";
      cin >> c;
      cout << "Your temperature, " << c << "C converts to " << c+273 << "K (Kelvin)" << endl;
      cout << "Your temperature also converts to: " << 1.8*c+32 << "F";
    }
    I was just thinking about revolving my code around temperature conversion.
    I changed some of it yesterday and forgot how I had it, so now it doesn't run. How can I define c? Is there anyway for me to put it in a "class."

    I also read about overloading in the book but I didn't really understand it and I have no idea what the last topic in the midterm requirements is about.

    So, can anyone please help me? I would really appreciate it.

  2. #2
    Join Date
    Oct 2005
    Location
    Australia
    Posts
    46

    Re: Help with a MidTerm - Simple programming

    oh dear, If you don't know that much then your book musn't be very good. To declare c put the line
    int c;
    as the first line of main.

    I recommend getting a better book. Try c++ for dummies. It explains classes pretty well and all the other stuff pretty well.

  3. #3
    Join Date
    Jan 2006
    Posts
    3

    Re: Help with a MidTerm - Simple programming

    Heh, like I didn't tell my instructor that millions of times. She made us buy Sams Learn C++ in 24 hrs and then switched to another book. I also tried putting int c; into main but it didn't render any results.
    Only:
    Code:
    bcc32 -D_DEBUG -g100 -j25 -Od -r- -k -y -v -vi- -tWC -c -IC:\CBuilderX\include -oG:\C++\wow\windows\Debug_Build\wow.obj   wow.cpp 
    Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
    wow.cpp:
    ilink32 -D -ap -Tpe -x -Gn -v -LC:\CBuilderX\lib  c0x32.obj windows\Debug_Build\wow.obj,G:\C++\wow\windows\Debug_Build\wow.exe,,cw32.lib import32.lib,, 
    Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland
    
    Fatal: Too many EXE file names: \wow\windows\Debug_Build\wow.exe
    
     ILINK32 exited with error code: 2
    Build cancelled due to errors

  4. #4
    Join Date
    Aug 2003
    Posts
    938

    Re: Help with a MidTerm - Simple programming

    Read this site, they have most of the topics you need to know, and have tutorials that are sometimes better then explanations from the books:
    http://www.cprogramming.com/tutorial.html

  5. #5
    Join Date
    Jan 2006
    Posts
    3

    Re: Help with a MidTerm - Simple programming

    Thanks, let's see if it helps. Do you know what might be causing my error?

  6. #6
    Join Date
    Aug 2003
    Posts
    938

    Re: Help with a MidTerm - Simple programming

    this is the simplest program possible.
    If you read a book this will be the first program that has nay input in it at all.
    Code:
    #include <iostream.h>
    //You have to have this so u can write cout<< instead of std::cout<<
    using namespace std;
    int main () {
      //Make a variable with original value of 0.  
      int c=0;  
      cout << "Enter a degree of temperature in Celsius: ";
      cin >> c;
      cout << "Your temperature, " << c << "C converts to " << c+273 << "K (Kelvin)" << endl;
      cout << "Your temperature also converts to: " << 1.8*c+32 << "F"<<endl;
      //OUtputs press any key to continue msg so the program doesn;t close automatically. Another possibility
      //Is to run your program from cmd. 
      system("pause");
      return 0;
    }
    Read the Sam 24 c++ book again, and write all of the code that it has and play around with it, because stuff like this is the very basicis...of the language, also read the site i gave u it has similar explanataions.

  7. #7
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Help with a MidTerm - Simple programming

    A small remark: It should be #include <iostream> instead of #include <iostream.h>
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  8. #8
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Help with a MidTerm - Simple programming

    Any book that claims to be able to teach you C++ in 24 hours is either very naive or lying.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  9. #9
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Help with a MidTerm - Simple programming

    Quote Originally Posted by Graham
    Any book that claims to be able to teach you C++ in 24 hours is either very naive or lying.
    Exactly, however, I think even a book that claims the above would still explain the following:
    • Functions and variables
    • Classes and Constructors
    • Operator Overloading
    • Initialization and Assignment
    Which is what the OP needs
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured