C Programming

These notes are in addition to the text book used in the class of BAA2013 Computer Programming in C++.

Tuesday, June 06, 2006

Project Supervision and Consultation

Project submission and consultation can be done at the following times:
Wednesday and Thursday (7-8 June 2006)
DK 3       :     9.00am-10.00am
DK 4       :     2.30pm - 3.30pm

Submission of Project 2

Please submit by the due date :
  1. the hardcopy of the report
  2. the softcopy in the elearn "assignment"

Thursday, May 25, 2006

Project 1 and Project 2 Due Dates

Project 1 : Simply supported beam
Deadline: Tuesday 30th May, 4.00pm at DK 4

Project 2 :
Deadline : Tuesday 13th June 2006.,
4.00 pm

Classes on 29th-31st May 2006

Next week all classes will be combined for both sections : AC and AA

Monday 9.00am - 1.00pm at DK 3
Lessons 13 and 14

Tuesday 10.00am - 12.01 pm at DK3
Test 2, please bring along your laptops / notebooks

2.30pm - 4.00pm at DK4
Submission of Project 1

Wednesday
9.00am - 12.00pm DK 3
2.15pm - 4.15pm DK4
Project submission (and interview for group projects)

Tuesday, May 23, 2006

Function Exercise 1

Function celcius to convert the temprature value from fahrenheit to celcius. This function is to receive an input and return a value.

Function Exercise 2

Function to calculate the area of a circle. This function will receive a value but return no value. The function will print the result of the calculation in the body of the function.

Function Exercise 3



Problem : Simply supported beam.
One point load.
Write the respective functions for the simply supported beam as shown in the diagram

1. Function to calculate the reactions, prints the reactions of both supports and returns the value of R of left support
2. Function to calculate and print the SFs (4)
3. Function to calculate and print the BM at point load position and mid-span

Monday, May 22, 2006

Test 1

Test 1 will be held on Thursday 25th May 2006
at 2.15pm

Topics will be from Lesson 1 to Lesson 8

Flow chart for Nested Loop


Write a program that uses nested loops to produce the following output:

A1B1C1C2C3A1B2C1C2C3A1B3C1C2C3
A2B1C1C2C3A2B2C1C2C3A2B3C1C2C3
A3B1C1C2C3A3B2C1C2C3A3B3C1C2C3

Sunday, May 21, 2006

max and minimum number

Store the max and minimum numbers in their respective declared variable

void main()
{
int Num;
int Max=0;
int Min=1000;
//

cin>>Num;
if (Num > Max)
Max=Num;
if (Num < Min)
Min=Num;
//
}

Saturday, May 20, 2006

Project 1 : Simply Supported Beam

This is a series of questions / mini projects given to you after every lesson starting from Lesson 5.

For each set of questions you will need to:-
1. submit a report which has to consist of the following four (4) elements:
a. defining diagram of the problem
b. flow-chart or algorithmn
c. Pseudo Code
d. source code

2. all mini projects will be evaluated to be in running properly during hands-on session class in the following respective lesson, (for example project given in Lesson 6 will be evaluated during the next class, ie Lesson 7).

If you have any questions, please post in the "comments" of this section.

Wednesday, May 10, 2006

output special characters and format

Special characters



Character sequence
Result

\n
Moves cursor to next line (same effect as endl

\t
Generates a tab character to move the cursor to the next tab stop

\\
Prints a backslash (\)

\’
Prints a single quotation mark (‘)

\”
Prints a double quotation mark (“)







Formatting options


Option
Description

left
Left justifies the output

right
Right justifies the output

showpoint
Displays decimal point and trailing zeros for all floating point numbers, even if the decimal places are not needed

uppercase
Desplays the “e” in E-notation as “E” rather than “e”

showpos
Desplays a leading plus sign before positive values

scientific
Displays floating point numbers in scientific (“E”) notation

fixed
Displays floating point numbers in normal notation

Lesson 5 input and output


Example of using special characters


// specchar.cpp
// example of new line and special characters
#include
int main()
{
j=25;
cout<< j<< ‘\n’; //single quotes because it is a single character
cout<< “String\n”; //double quotes because it is part of a string
cout << “The numbers on the following line are separated by tabs.\n”;
cout << “1 \t 2 \t 3 \t 4 \n”;
// the following lines use endl
cout << “in C++, you output backslashes (\\)” << endl;
cout << “you can also print single quotes (\’) and “ << endl;
cout << “double quotes (\”).” << endl;
return 0;
}

Example of formatted output

// coutsetf.cpp
#include
int main()
{
float x = 24.0;
cout << x << endl; //displays 24
cout.setf(ios::showpoint);
cout << x << endl; // displays 24.0000
cout.setf(ios::showpos);
cout << x << endl; // displays +24.00
cout.setf(ios::scientific);
cout << x << endl; // displays +2.400000e+001
return 0;
}