Register to reply

[C++] Tutorial 1: Discussion

by dduardo
Tags: discussion, tutorial
Share this thread:
Adam Y.
#55
Mar25-05, 09:35 PM
P: 14
Quote Quote by Hurkyl
Not to mention that it's not free!

I thought QBASIC was a beautiful language, is VB really that bad? (Of course, I had not yet heard of Pascal or C++ at that time in my life)
Oddly enough that's not entirely true. .net express
gsolvers
#56
Jun7-05, 01:15 AM
P: 2
i am creating two fileds a header file function.h with function wel() defined in it and a main file main.c which is calling wel() function define inside function.h. Hope this is enough.
function.h
public void wel()
{
printf("Hello Welcome !");
}

main.c

# "header.h"
int main(int argc, char *argv[])
{
wel();
return 0;
}
neurocomp2003
#57
Jun7-05, 12:28 PM
P: 1,373
people shouhld alwasy start with pascal =]
arloane
#58
Aug3-05, 03:16 PM
P: 1
Quote Quote by dduardo
Please post your C++ questions or comments here for Tutorial 1.
I am having trouble getting my multidimensional array to do what I want it to do. Here is an exmple
of how I want this to look and how it will work.

row 1) Part Description | Part number //this is multidemsional array PD( row 1,columns 1-18 ), m array P#

row 2) Cam | 2110 // PD [1][0-4],Cam[1][0-4]

row 3) air filter | 1111 // PD [2][0-10],cam[2][0-4]
ect

My goal is on the first time the order function is entered to have row 1 and 2 display, the 2nd time the order function is entered rows 1,2,3 will display, the third rows 1,2,3,4 ect. Also the array will only display addresses not what it is supposed to. I know this is not an easy thing to do but I am not able to think of any other way to show all of the ordered items. Helllllllllllp plllllllllllllllease...........

here is the code I have.

#include <iostream>
#include <iomanip>
#include <ctype.h>
#include <stdlib.h>
using namespace std;

void partsorder(char order[]);
void list(char order[]);
int zz = 0;
const int ROWS = 50;
const int COLS = 50;
const int CAM = 20;

int main()
{
char shaft[CAM]="";

do
{
cout << "The cam number is 2110. The cam kit number is 2110k. Please enter\n"
<< "the approiate part number ";
cin.getline(shaft,CAM);
if (shaft[0] != 0) //if shaft is not null then goto
list(shaft);
}while(shaft[0] != 0);
}

void list(char order[])
{
if (zz == 0){
cout << " | Part Description |" << " Part # |\n ";
partsorder(order);
}
else {
partsorder(order);
}
}

void partsorder(char order[])
{
int num = 0, e = strlen(order);
num = atoi(order);
char c[CAM] = "Cam";
char ck[CAM] = "Cam kit";
char b,pd[ROWS][COLS];
zz++;

switch (num)
{
case 2110:
if (e == 4){
for(int y = 0; y < COLS; y++){
pd[zz][y]=c[y];

}
//strcpy(pd,c);
b = ' ';
//cout << "Please enter the quantity -->";
//cin >> q;
//price = 86 * q;
break;
}

else if (e == 5) {
for(int y = 0; y < COLS; y++){
pd[zz][y]=c[y];
}
//strcpy(pd,ck);
b = 'k';
//cout << "Please enter the quantity -->";
//cin >> q;
//price = 136 * q;
}
}
int x = 0;
for(int y = 0; y < COLS; y++){
cout << pd << endl;
for (x = 0; x <= zz; x++){
//cout << " | " << setw(16)<< setiosflags(ios::left) << pd [x][y]<< " | " << setw(5) << num << b << endl;
}
}
}
JamesU
#59
Aug11-05, 05:54 PM
PF Gold
JamesU's Avatar
P: 745
no updates....
Grotesque Puppet
#60
Aug11-05, 06:03 PM
P: 42
Example

Number = 65536

log(65536)/log(2) = 16 bits = (16/8) bytes = 2 bytes
A 16-bit (2 byte) number ranges from 0 to 65535, or -32768 to 32767 depending if its signed or unsigned. To hold 65536 would require 17 bits.
Diane_
#61
Oct12-05, 02:28 AM
HW Helper
P: 401
Maybe I'm in the wrong place, but what the heck. In the basic tutorial, you mention that the int is usually 4 bytes. I don't know if it's something you want to get into, but it is compiler-dependent. I had occasion to use the Borland compiler a few years ago, and ints were all over the place. Sometimes they were longs, sometimes they were shorts, and I never did find a pattern to it. I finally gave up declaring ints at all and went straight to longs and shorts.

For what it's worth...
jim mcnamara
#62
Oct12-05, 09:25 AM
Sci Advisor
PF Gold
P: 1,379
The same problem obtains in a 64 bit environment where longs are 64 bits.
The Borland compilers are 16 bit, which is what MS-DOS and consumer Windows (Win95, Win98, WinME) are built on top of.
dduardo
#63
Nov20-05, 08:35 PM
Emeritus
dduardo's Avatar
P: 1,919
I finally finished the basic c++ tutorial. If your interested in a particular topic in programming let me know and i'll see if I can accommodate you.
exequor
#64
Nov21-05, 08:54 PM
exequor's Avatar
P: 393
dduardo, it was a really good tutorial. Apart from the basics what else do you think would be good to know to solve problems using c++; such as for the acm programming contest? Do you plan to have an intermediate tutorial?
dduardo
#65
Nov21-05, 09:13 PM
Emeritus
dduardo's Avatar
P: 1,919
For the intermediate I'll do pointers, strings, basic classes, structures and file io.

Then for advanced I'll do overloading, polymorphism, virtual and templates.

I could also do a tutorial just on alorithms: sorting, trees, heaps, queues, stacks, etc.

I could also do special topics like posix threads, interprocess communication (IPC), x86 asm, etc.

In terms of ACM programming you would want a tutorial on dynamic programming. I know when I did ACM that was a big topic.

Which one do you want?
ranger
#66
Nov21-05, 09:39 PM
PF Gold
ranger's Avatar
P: 1,685
How about a topic covering math functions, Stuff like trigonometry and so on?
dduardo
#67
Nov22-05, 05:36 AM
Emeritus
dduardo's Avatar
P: 1,919
I could add math functions to intermediate and dynamic memory allocation to advanced.
Mattara
#68
Jan7-06, 09:13 AM
P: 398
Without putting too much pressure/workload on you dduardo , i would like to see as much included as possible to make the tutorial show most sides of c++ programming and the different aspects of it.

My suggestion is to try and cover as much as possible as clearly as possible as you have done so far. I like the fact that the posts are not several pages long but gives a more-than-basic idea about the specific topic and it is up to the reader to go and try for themselves a bit instead of reading every program code out of a book.

Great tutorial
eunhye732
#69
Feb23-06, 01:17 AM
P: 12
This is my first time using a C++ program...actually any programs. my C++ programming class is a lot harder than my physics and math classes. =(
i've never struggled so much so i would REALLY REALLY appreciate as much help as possible. here is my problem:

Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done, report to the user the position of the first 7 entered and the last 7 entered. By position we mean, for example, that if the first 7 is the 2nd number entered then its position would be 2.

Sample screen output 1:

How many numbers will be entered? 8
Enter num: 5
Enter num: 7
Enter num: 6
Enter num: 7
Enter num: 7
Enter num: 3
Enter num: 8
Enter num: 6
The first 7 was in position 2
The last 7 was in position 5


Sample screen output 2:

How many numbers will be entered? 8
Enter num: 5
Enter num: 2
Enter num: 6
Enter num: 7
Enter num: 1
Enter num: 3
Enter num: 8
Enter num: 6
The first 7 was in position 4
The last 7 was in position 4


Sample screen output 3:


How many numbers will be entered? 8
Enter num: 5
Enter num: 1
Enter num: 6
Enter num: 5
Enter num: 9
Enter num: 3
Enter num: 8
Enter num: 6
Sorry, no sevens were entered.


All i know is that for the counter controlled loop, I use the For loop and include the if-else statement inside the loop. I just can't get the problem to tell me the positions for both 7s.
thanks again.
eunhye732
#70
Feb23-06, 01:25 AM
P: 12
if this was a wrong place to put my question, can you tell me where? Thanks
TenaliRaman
#71
Feb23-06, 10:50 PM
P: 646
I will do it by keeping two variables,
1. min_pos - will hold the position of first 7
2. max_pos - will hold the position of last 7

Steps :
1. Initialise min_pos and max_pos to -1
2. Whenever a 7 is read,
if min_pos = -1, update min_pos = counter
if counter > max_pos, update max_pos = counter
3. if both min_pos = -1, output no 7 was read
otherwise output min_pos and max_pos

Once you are done with the program, read the program carefully. Try to understand how the value of -1 was being used here. Such techniques are commonplace in many programs, so it should help you out.

-- AI
scott1
#72
Mar21-06, 06:54 PM
P: 459
I need help with tutorial.I'am working a assigment 1.I enterd this in the Bloodshed Dev C++.
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
    char myCharacter = 'z';
    cout << "The datatype is" << sizeof(int) << " bytes!" << endl;
    cout << " the varible has a value of " << myCharacter << endl;
    return 0;

}
It works kind of.For some starge reason the box pops up but it closes as soon as it opens.


Register to reply

Related Discussions
CFD tutorial Mechanical Engineering 4
C# Tutorial Programming & Computer Science 13
GR Tutorial Special & General Relativity 2
Probability tutorial Academic Guidance 0
Tutorial La Tec General Math 1