# [C++] Tutorial 1: Discussion

by dduardo
Tags: discussion, tutorial
P: 14
 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
 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; }
P: 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;
}
}
}
 PF Gold P: 745 no updates....
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.
 HW Helper P: 402 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...
 Sci Advisor PF Gold P: 1,342 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.
 Emeritus 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.
 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?
 Emeritus 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?
 PF Gold P: 1,686 How about a topic covering math functions, Stuff like trigonometry and so on?
 Emeritus P: 1,919 I could add math functions to intermediate and dynamic memory allocation to advanced.
 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
 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.
 P: 12 if this was a wrong place to put my question, can you tell me where? Thanks
 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
 P: 459 I need help with tutorial.I'am working a assigment 1.I enterd this in the Bloodshed Dev C++. #include #include 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.

 Related Discussions Mechanical Engineering 4 Programming & Computer Science 13 Special & General Relativity 2 Academic Guidance 0 General Math 1