Showing posts with label 17/18 SEM 1 BCS1013. Show all posts
Showing posts with label 17/18 SEM 1 BCS1013. Show all posts

12/04/2017

BCS 1013 PSCP. Lab File Input and File Output

1. Consider the following C++ program. What is the content of "test.txt".

#include
#include

using namespace std;
int main(int argc, char *argv[])
{
   ofstream out("test.txt");
   out << 10 << " " << 123.23 << "\n";
   out << "This is a short text file.";
   out.close();
   system("PAUSE");
   return EXIT_SUCCESS;

}


2. Write a program that prompts user to enter:-

    Name
    Age
    State
    Country

and write into a file named biodata.txt as follows.


Name   : Ahmad Ashraaf
Age    : 19
State  : terengganu
Country: Malaysia

3. The following program is supposed to read two numbers from a file named input.dat and write the sum of the numbers to a file named output.dat. However, it fails to do so. Rewrite the program so that it accomplishes whatit is intended to do. (Also, include statements to close the files.)

#include
#include
using namespace std;
int main()
{
int num1, num2;
ifstream infile;
outfile.open("output.dat");
infile >> num1 >> num2;
outfile << "Sum = " << num1 + num2 << endl;
return 0;
}


4. Assume that each of the following statements applies to the same program.

i)   Write a statement that opens file oldmast.dat for input; use an ifstream object called inOldMaster.

ii)  Write a statement that opens file trans.dat for input; use an ifstream object called inTransaction.

iii) Write a statement that opens file newmast.dat for output , use ofstream object outNewMaster.

iv) Write a statement that reads a record from the file oldmast.dat. The record consists of integer accountNumber, string name and floating-point currentBalance; use ifstream object inOldMaster.

9/18/2017

BCS1013 Lab 21 Sept 2017


1. Design an algorithm and write a C++ program  that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive, negative, or zero.


2. Design an algorithm and write a C++ program  that prompts the user to input two numbers. The program should then output the numbers in ascending order.


3. Design an algorithm and write a C++ program  that prompts the user to input three numbers. The program should then output the numbers in ascending order.

4. Run the following program using several input such as 163, 200, 35.\

#include
#include
#include

using namespace std;

int main(int argc, char *argv[])
{
    int  RM, RM100 , RM50, RM10 , RM20, RM5, RM1 ,Baki ,Baki1, Baki2, Baki3;
    cout << "RM ";
    cin >> RM;
    RM100 = RM/100;
    Baki = RM%100;
    RM50 = Baki/50;
    Baki1 = Baki%50;
    RM20 = Baki1/20;
    Baki2 = Baki1%20;
    RM10 = Baki2/10;
    Baki3 = Baki2%10;
    RM5 = Baki3/5;
    RM1 = Baki3%5;
   
    cout << "Amount of RM100: " << RM100 << endl;
    cout << "Amount of RM50: " << RM50 << endl;
    cout << "Amount of RM20: " << RM20 <    cout << "Amount of RM10: " << RM10 << endl;
    cout << "Amount of RM5: " << RM5 << endl;
    cout << "Amount of RM1: " << RM1 << endl;
   
    system("PAUSE");
    return EXIT_SUCCESS;
}
 

9/10/2017

DCT1144 Programming Fundamentals LAB 11 Sept 2017

1. Design an algorithm and write a C++ program to find the perimeter and area of a rectangle. The perimeter and area of the rectangle are given by the following formulas:
    perimeter = 2 * (length + width)
    area = length * width

Algorithm
1. Get length of the rectangle
2. Get width of the rectangle
3. Find the perimeter using the following equation:
    perimeter = 2 * (length + width)
4. Find the area using the following equation:
    area = length * width
5. Print perimeter and area


C++ Program

#include
#include

using namespace std;

int main(int argc, char *argv[])
{
   int length, width, Perimeter, Area;
   cout<<" Please enter length and width of a rectangle \n";
   cin>>length;
   cin>>width;
   Perimeter = 2* (length + width);
   Area = length * width;
    cout<<"Perimeter of a rectangle = "<    cout<<"\n Area of a rectangle = "<    system("PAUSE");
    return EXIT_SUCCESS;
}



2. Design an algorithm and write a C++ program that reads a Fahrenheit degree in double, then converts it to Celsius and displays the result in a message dialog box. The formula for the conversion is as follows:

celsius = (5/9) * (fahrenheit - 32)


3. Design an algorithm and write a C++ program  that calculates the sales tax and the price of an item sold in a particular state State’s portion of the sales tax is 4% City’s portion of the sales tax is 1.5% If the item is a luxury item, then there is a 10% luxury tax.


4. Design an algorithm and write a C++ program that input two integers and find the largest.

9/04/2017

BCS1013 Problem Solving and Computer Programming 2017 2018 Sem 1

 Berikut adalah bahan-bahan yang akan di gunakan untuk BCS1013 Problem Solving and Computer Programming 2017 2018 Sem 1. 
 

2.Powerpoint Slides
Introduction to Algorithm (Flowchart and Pseudocode)
 
4. Editor untuk menulis program. Perisian Dev-C++ akan di gunakan untuk menulis aturcara. Perisian telah tersedia di Makmal. Jika pelajar ingin memasang (install) pada komputer sendiri, sila download dari pautan berikut:  http://www.bloodshed.net/dev/index.html. Rujuk cara memasang pada pautan berikut: https://ceng230.ceng.metu.edu.tr/Compilers/dev-cpp.html

Cara download Installer windows 10 dalam format ISO

1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan.  ...