|
-
January 10th, 2006, 04:09 PM
#1
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.
-
January 10th, 2006, 07:15 PM
#2
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.
-
January 10th, 2006, 07:42 PM
#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
-
January 10th, 2006, 08:01 PM
#4
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
-
January 10th, 2006, 08:34 PM
#5
Re: Help with a MidTerm - Simple programming
Thanks, let's see if it helps. Do you know what might be causing my error?
-
January 10th, 2006, 09:19 PM
#6
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.
-
January 11th, 2006, 03:57 AM
#7
Re: Help with a MidTerm - Simple programming
A small remark: It should be #include <iostream> instead of #include <iostream.h>
-
January 11th, 2006, 04:44 AM
#8
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
-
January 11th, 2006, 07:40 AM
#9
Re: Help with a MidTerm - Simple programming
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|