Click to See Complete Forum and Search --> : Help with a MidTerm - Simple programming


Psyc
January 10th, 2006, 03:09 PM
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:

#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.

jarro_2783
January 10th, 2006, 06:15 PM
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.

Psyc
January 10th, 2006, 06:42 PM
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:

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

Quell
January 10th, 2006, 07:01 PM
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

Psyc
January 10th, 2006, 07:34 PM
Thanks, let's see if it helps. Do you know what might be causing my error?

Quell
January 10th, 2006, 08:19 PM
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.
#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.

Marc G
January 11th, 2006, 02:57 AM
A small remark: It should be #include <iostream> instead of #include <iostream.h>

Graham
January 11th, 2006, 03:44 AM
Any book that claims to be able to teach you C++ in 24 hours is either very naive or lying.

Marc G
January 11th, 2006, 06:40 AM
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 :wave: